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
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
2014-01-19 23:14:24 +11:00
|
|
|
*
|
|
|
|
|
* Utility functions for dealing with OpenGL texture & material context,
|
|
|
|
|
* mipmap generation and light objects.
|
|
|
|
|
*
|
2018-04-16 14:07:42 +02:00
|
|
|
* These are some obscure rendering functions shared between the game engine (not anymore)
|
|
|
|
|
* and the blender, in this module to avoid duplication
|
2014-01-19 23:14:24 +11:00
|
|
|
* and abstract them away from the rest a bit.
|
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 <string.h>
|
|
|
|
|
|
2013-06-15 14:01:16 +00:00
|
|
|
#include "BLI_blenlib.h"
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
#include "BLI_boxpack_2d.h"
|
2013-06-15 14:01:16 +00:00
|
|
|
#include "BLI_linklist.h"
|
Changes to Color Management
After testing and feedback, I've decided to slightly modify the way color
management works internally. While the previous method worked well for
rendering, was a smaller transition and had some advantages over this
new method, it was a bit more ambiguous, and was making things difficult
for other areas such as compositing.
This implementation now considers all color data (with only a couple of
exceptions such as brush colors) to be stored in linear RGB color space,
rather than sRGB as previously. This brings it in line with Nuke, which also
operates this way, quite successfully. Color swatches, pickers, color ramp
display are now gamma corrected to display gamma so you can see what
you're doing, but the numbers themselves are considered linear. This
makes understanding blending modes more clear (a 0.5 value on overlay
will not change the result now) as well as making color swatches act more
predictably in the compositor, however bringing over color values from
applications like photoshop or gimp, that operate in a gamma space,
will give identical results.
This commit will convert over existing files saved by earlier 2.5 versions to
work generally the same, though there may be some slight differences with
things like textures. Now that we're set on changing other areas of shading,
this won't be too disruptive overall.
I've made a diagram explaining the pipeline here:
http://mke3.net/blender/devel/2.5/25_linear_workflow_pipeline.png
and some docs here:
http://www.blender.org/development/release-logs/blender-250/color-management/
2009-12-02 07:56:34 +00:00
|
|
|
#include "BLI_math.h"
|
2013-06-15 14:01:16 +00:00
|
|
|
#include "BLI_threads.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
Changes to Color Management
After testing and feedback, I've decided to slightly modify the way color
management works internally. While the previous method worked well for
rendering, was a smaller transition and had some advantages over this
new method, it was a bit more ambiguous, and was making things difficult
for other areas such as compositing.
This implementation now considers all color data (with only a couple of
exceptions such as brush colors) to be stored in linear RGB color space,
rather than sRGB as previously. This brings it in line with Nuke, which also
operates this way, quite successfully. Color swatches, pickers, color ramp
display are now gamma corrected to display gamma so you can see what
you're doing, but the numbers themselves are considered linear. This
makes understanding blending modes more clear (a 0.5 value on overlay
will not change the result now) as well as making color swatches act more
predictably in the compositor, however bringing over color values from
applications like photoshop or gimp, that operate in a gamma space,
will give identical results.
This commit will convert over existing files saved by earlier 2.5 versions to
work generally the same, though there may be some slight differences with
things like textures. Now that we're set on changing other areas of shading,
this won't be too disruptive overall.
I've made a diagram explaining the pipeline here:
http://mke3.net/blender/devel/2.5/25_linear_workflow_pipeline.png
and some docs here:
http://www.blender.org/development/release-logs/blender-250/color-management/
2009-12-02 07:56:34 +00:00
|
|
|
|
2019-12-17 11:11:15 +11:00
|
|
|
#include "DNA_image_types.h"
|
|
|
|
|
#include "DNA_movieclip_types.h"
|
|
|
|
|
#include "DNA_userdef_types.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 "MEM_guardedalloc.h"
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
#include "IMB_colormanagement.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 "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BKE_main.h"
|
2019-04-02 16:05:22 +02:00
|
|
|
#include "BKE_movieclip.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
|
|
|
|
2010-07-14 10:46:12 +00:00
|
|
|
#include "GPU_draw.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_extensions.h"
|
2018-08-14 16:07:19 -03:00
|
|
|
#include "GPU_glew.h"
|
2019-10-03 16:21:23 +02:00
|
|
|
#include "GPU_platform.h"
|
2015-12-06 21:20:19 +01:00
|
|
|
#include "GPU_texture.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
|
|
|
|
2014-05-22 11:58:07 +10:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
2019-02-18 13:23:49 +01:00
|
|
|
static void gpu_free_image_immediate(Image *ima);
|
|
|
|
|
|
2018-04-16 14:07:42 +02:00
|
|
|
//* Checking powers of two for images since OpenGL ES requires it */
|
2017-03-02 00:36:33 +11:00
|
|
|
#ifdef WITH_DDS
|
2017-02-23 11:03:56 +01:00
|
|
|
static bool is_power_of_2_resolution(int w, int 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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return is_power_of_2_i(w) && is_power_of_2_i(h);
|
2013-03-15 16:16:11 +00:00
|
|
|
}
|
2017-03-02 00:36:33 +11:00
|
|
|
#endif
|
2009-08-16 01:25:53 +00:00
|
|
|
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
static bool is_over_resolution_limit(GLenum textarget, int w, int h)
|
2013-03-15 16:16:11 +00:00
|
|
|
{
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
int size = (textarget == GL_TEXTURE_CUBE_MAP) ? GPU_max_cube_map_size() : GPU_max_texture_size();
|
2019-04-17 06:17:24 +02:00
|
|
|
int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, size) : size;
|
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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (w > reslimit || h > reslimit);
|
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-15 16:16:11 +00:00
|
|
|
static int smaller_power_of_2_limit(int num)
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, GPU_max_texture_size()) :
|
|
|
|
|
GPU_max_texture_size();
|
|
|
|
|
/* take texture clamping into account */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (num > reslimit) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return reslimit;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
return power_of_2_min_i(num);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Current OpenGL state caching for GPU_set_tpage */
|
|
|
|
|
|
|
|
|
|
static struct GPUTextureState {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* also controls min/mag filtering */
|
|
|
|
|
bool domipmap;
|
|
|
|
|
/* only use when 'domipmap' is set */
|
|
|
|
|
bool linearmipmap;
|
|
|
|
|
/* store this so that new images created while texture painting won't be set to mipmapped */
|
|
|
|
|
bool texpaint;
|
|
|
|
|
|
|
|
|
|
float anisotropic;
|
2019-01-16 15:10:19 +01:00
|
|
|
} GTS = {1, 0, 0, 1.0f};
|
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
|
|
|
|
|
|
|
|
/* Mipmap settings */
|
|
|
|
|
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_set_mipmap(Main *bmain, bool 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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (GTS.domipmap != mipmap) {
|
|
|
|
|
GPU_free_images(bmain);
|
|
|
|
|
GTS.domipmap = 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
|
|
|
}
|
|
|
|
|
|
2015-04-28 01:03:28 +10:00
|
|
|
void GPU_set_linear_mipmap(bool linear)
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (GTS.linearmipmap != linear) {
|
|
|
|
|
GTS.linearmipmap = linear;
|
|
|
|
|
}
|
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-28 01:03:28 +10:00
|
|
|
bool GPU_get_mipmap(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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return GTS.domipmap && !GTS.texpaint;
|
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-28 01:03:28 +10:00
|
|
|
bool GPU_get_linear_mipmap(void)
|
2013-04-14 00:40:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return GTS.linearmipmap;
|
2013-04-14 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-28 01:03:28 +10:00
|
|
|
static GLenum gpu_get_mipmap_filter(bool mag)
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* linearmipmap is off by default *when mipmapping is off,
|
|
|
|
|
* use unfiltered display */
|
|
|
|
|
if (mag) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (GTS.domipmap) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return GL_LINEAR;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return GL_NEAREST;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (GTS.domipmap) {
|
|
|
|
|
if (GTS.linearmipmap) {
|
|
|
|
|
return GL_LINEAR_MIPMAP_LINEAR;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return GL_LINEAR_MIPMAP_NEAREST;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return GL_NEAREST;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2011-06-15 18:59:22 +00:00
|
|
|
/* Anisotropic filtering settings */
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_set_anisotropic(Main *bmain, float value)
|
2011-06-15 18:59:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (GTS.anisotropic != value) {
|
|
|
|
|
GPU_free_images(bmain);
|
2011-06-15 18:59:22 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Clamp value to the maximum value the graphics card supports */
|
|
|
|
|
const float max = GPU_max_texture_anisotropy();
|
2019-04-22 09:32:37 +10:00
|
|
|
if (value > max) {
|
2019-04-17 06:17:24 +02:00
|
|
|
value = max;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2011-06-15 18:59:22 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GTS.anisotropic = value;
|
|
|
|
|
}
|
2011-06-15 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-28 05:06:30 +00:00
|
|
|
float GPU_get_anisotropic(void)
|
2011-06-15 18:59:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return GTS.anisotropic;
|
2011-06-15 18:59: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
|
|
|
/* Set OpenGL state for an MTFace */
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget)
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
{
|
2019-04-22 09:32:37 +10:00
|
|
|
if (textarget == GL_TEXTURE_2D) {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
return &ima->gputexture[TEXTARGET_TEXTURE_2D];
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
else if (textarget == GL_TEXTURE_CUBE_MAP) {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
return &ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP];
|
|
|
|
|
}
|
|
|
|
|
else if (textarget == GL_TEXTURE_2D_ARRAY) {
|
|
|
|
|
return &ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY];
|
|
|
|
|
}
|
|
|
|
|
else if (textarget == GL_TEXTURE_1D_ARRAY) {
|
|
|
|
|
return &ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING];
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
}
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
static uint gpu_texture_create_tile_mapping(Image *ima)
|
|
|
|
|
{
|
|
|
|
|
GPUTexture *tilearray = ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY];
|
|
|
|
|
if (tilearray == NULL) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float array_w = GPU_texture_width(tilearray);
|
|
|
|
|
float array_h = GPU_texture_height(tilearray);
|
|
|
|
|
|
|
|
|
|
ImageTile *last_tile = ima->tiles.last;
|
|
|
|
|
/* Tiles are sorted by number. */
|
|
|
|
|
int max_tile = last_tile->tile_number - 1001;
|
|
|
|
|
|
|
|
|
|
/* create image */
|
|
|
|
|
int bindcode;
|
|
|
|
|
glGenTextures(1, (GLuint *)&bindcode);
|
|
|
|
|
glBindTexture(GL_TEXTURE_1D_ARRAY, bindcode);
|
|
|
|
|
|
|
|
|
|
int width = max_tile + 1;
|
|
|
|
|
float *data = MEM_callocN(width * 8 * sizeof(float), __func__);
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
|
data[4 * i] = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
|
|
|
|
|
int i = tile->tile_number - 1001;
|
|
|
|
|
data[4 * i] = tile->runtime.tilearray_layer;
|
|
|
|
|
|
|
|
|
|
float *tile_info = &data[4 * width + 4 * i];
|
|
|
|
|
tile_info[0] = tile->runtime.tilearray_offset[0] / array_w;
|
|
|
|
|
tile_info[1] = tile->runtime.tilearray_offset[1] / array_h;
|
|
|
|
|
tile_info[2] = tile->runtime.tilearray_size[0] / array_w;
|
|
|
|
|
tile_info[3] = tile->runtime.tilearray_size[1] / array_h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA32F, width, 2, 0, GL_RGBA, GL_FLOAT, data);
|
|
|
|
|
MEM_freeN(data);
|
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_1D_ARRAY, 0);
|
|
|
|
|
|
|
|
|
|
return bindcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct PackTile {
|
|
|
|
|
FixedSizeBoxPack boxpack;
|
|
|
|
|
ImageTile *tile;
|
|
|
|
|
float pack_score;
|
|
|
|
|
} PackTile;
|
|
|
|
|
|
|
|
|
|
static int compare_packtile(const void *a, const void *b)
|
|
|
|
|
{
|
|
|
|
|
const PackTile *tile_a = a;
|
|
|
|
|
const PackTile *tile_b = b;
|
|
|
|
|
|
|
|
|
|
return tile_a->pack_score < tile_b->pack_score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
|
|
|
|
|
{
|
|
|
|
|
int arraywidth = 0, arrayheight = 0;
|
|
|
|
|
|
|
|
|
|
ListBase boxes = {NULL};
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
|
|
|
|
|
ImageUser iuser;
|
|
|
|
|
BKE_imageuser_default(&iuser);
|
|
|
|
|
iuser.tile = tile->tile_number;
|
|
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
|
|
|
|
|
|
|
|
|
if (ibuf) {
|
|
|
|
|
PackTile *packtile = MEM_callocN(sizeof(PackTile), __func__);
|
|
|
|
|
packtile->tile = tile;
|
|
|
|
|
packtile->boxpack.w = ibuf->x;
|
|
|
|
|
packtile->boxpack.h = ibuf->y;
|
|
|
|
|
|
|
|
|
|
if (is_over_resolution_limit(
|
|
|
|
|
GL_TEXTURE_2D_ARRAY, packtile->boxpack.w, packtile->boxpack.h)) {
|
|
|
|
|
packtile->boxpack.w = smaller_power_of_2_limit(packtile->boxpack.w);
|
|
|
|
|
packtile->boxpack.h = smaller_power_of_2_limit(packtile->boxpack.h);
|
|
|
|
|
}
|
|
|
|
|
arraywidth = max_ii(arraywidth, packtile->boxpack.w);
|
|
|
|
|
arrayheight = max_ii(arrayheight, packtile->boxpack.h);
|
|
|
|
|
|
|
|
|
|
/* We sort the tiles by decreasing size, with an additional penalty term
|
|
|
|
|
* for high aspect ratios. This improves packing efficiency. */
|
|
|
|
|
float w = packtile->boxpack.w, h = packtile->boxpack.h;
|
|
|
|
|
packtile->pack_score = max_ff(w, h) / min_ff(w, h) * w * h;
|
|
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
|
|
|
|
BLI_addtail(&boxes, packtile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert(arraywidth > 0 && arrayheight > 0);
|
|
|
|
|
|
|
|
|
|
BLI_listbase_sort(&boxes, compare_packtile);
|
|
|
|
|
int arraylayers = 0;
|
|
|
|
|
/* Keep adding layers until all tiles are packed. */
|
|
|
|
|
while (boxes.first != NULL) {
|
|
|
|
|
ListBase packed = {NULL};
|
|
|
|
|
BLI_box_pack_2d_fixedarea(&boxes, arraywidth, arrayheight, &packed);
|
|
|
|
|
BLI_assert(packed.first != NULL);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (PackTile *, packtile, &packed) {
|
|
|
|
|
ImageTile *tile = packtile->tile;
|
|
|
|
|
int *tileoffset = tile->runtime.tilearray_offset;
|
|
|
|
|
int *tilesize = tile->runtime.tilearray_size;
|
|
|
|
|
|
|
|
|
|
tileoffset[0] = packtile->boxpack.x;
|
|
|
|
|
tileoffset[1] = packtile->boxpack.y;
|
|
|
|
|
tilesize[0] = packtile->boxpack.w;
|
|
|
|
|
tilesize[1] = packtile->boxpack.h;
|
|
|
|
|
tile->runtime.tilearray_layer = arraylayers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(&packed);
|
|
|
|
|
arraylayers++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create image */
|
|
|
|
|
int bindcode;
|
|
|
|
|
glGenTextures(1, (GLuint *)&bindcode);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, bindcode);
|
|
|
|
|
|
|
|
|
|
GLenum data_type, internal_format;
|
|
|
|
|
if (main_ibuf->rect_float) {
|
|
|
|
|
data_type = GL_FLOAT;
|
|
|
|
|
internal_format = GL_RGBA16F;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
data_type = GL_UNSIGNED_BYTE;
|
|
|
|
|
internal_format = GL_RGBA8;
|
|
|
|
|
if (!IMB_colormanagement_space_is_data(main_ibuf->rect_colorspace) &&
|
|
|
|
|
!IMB_colormanagement_space_is_scene_linear(main_ibuf->rect_colorspace)) {
|
|
|
|
|
internal_format = GL_SRGB8_ALPHA8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTexImage3D(GL_TEXTURE_2D_ARRAY,
|
|
|
|
|
0,
|
|
|
|
|
internal_format,
|
|
|
|
|
arraywidth,
|
|
|
|
|
arrayheight,
|
|
|
|
|
arraylayers,
|
|
|
|
|
0,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
data_type,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
|
|
|
|
|
int tilelayer = tile->runtime.tilearray_layer;
|
|
|
|
|
int *tileoffset = tile->runtime.tilearray_offset;
|
|
|
|
|
int *tilesize = tile->runtime.tilearray_size;
|
|
|
|
|
|
|
|
|
|
if (tilesize[0] == 0 || tilesize[1] == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageUser iuser;
|
|
|
|
|
BKE_imageuser_default(&iuser);
|
|
|
|
|
iuser.tile = tile->tile_number;
|
|
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
|
|
|
|
BLI_assert(ibuf != NULL);
|
|
|
|
|
|
|
|
|
|
bool needs_scale = (ibuf->x != tilesize[0] || ibuf->y != tilesize[1]);
|
|
|
|
|
|
|
|
|
|
ImBuf *scale_ibuf = NULL;
|
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
|
float *rect_float = ibuf->rect_float;
|
|
|
|
|
|
|
|
|
|
const bool store_premultiplied = ima->alpha_mode != IMA_ALPHA_STRAIGHT;
|
|
|
|
|
if (ibuf->channels != 4 || !store_premultiplied) {
|
|
|
|
|
rect_float = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__);
|
|
|
|
|
IMB_colormanagement_imbuf_to_float_texture(
|
|
|
|
|
rect_float, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float *pixeldata = rect_float;
|
|
|
|
|
if (needs_scale) {
|
|
|
|
|
scale_ibuf = IMB_allocFromBuffer(NULL, rect_float, ibuf->x, ibuf->y, 4);
|
|
|
|
|
IMB_scaleImBuf(scale_ibuf, tilesize[0], tilesize[1]);
|
|
|
|
|
pixeldata = scale_ibuf->rect_float;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
|
|
|
|
0,
|
|
|
|
|
tileoffset[0],
|
|
|
|
|
tileoffset[1],
|
|
|
|
|
tilelayer,
|
|
|
|
|
tilesize[0],
|
|
|
|
|
tilesize[1],
|
|
|
|
|
1,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_FLOAT,
|
|
|
|
|
pixeldata);
|
|
|
|
|
|
|
|
|
|
if (rect_float != ibuf->rect_float) {
|
|
|
|
|
MEM_freeN(rect_float);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
unsigned int *rect = ibuf->rect;
|
|
|
|
|
|
|
|
|
|
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
|
|
|
|
rect = MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__);
|
|
|
|
|
IMB_colormanagement_imbuf_to_byte_texture((uchar *)rect,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
ibuf->x,
|
|
|
|
|
ibuf->y,
|
|
|
|
|
ibuf,
|
|
|
|
|
internal_format == GL_SRGB8_ALPHA8,
|
|
|
|
|
ima->alpha_mode == IMA_ALPHA_PREMUL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int *pixeldata = rect;
|
|
|
|
|
if (needs_scale) {
|
|
|
|
|
scale_ibuf = IMB_allocFromBuffer(rect, NULL, ibuf->x, ibuf->y, 4);
|
|
|
|
|
IMB_scaleImBuf(scale_ibuf, tilesize[0], tilesize[1]);
|
|
|
|
|
pixeldata = scale_ibuf->rect;
|
|
|
|
|
}
|
|
|
|
|
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
|
|
|
|
0,
|
|
|
|
|
tileoffset[0],
|
|
|
|
|
tileoffset[1],
|
|
|
|
|
tilelayer,
|
|
|
|
|
tilesize[0],
|
|
|
|
|
tilesize[1],
|
|
|
|
|
1,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
|
pixeldata);
|
|
|
|
|
|
|
|
|
|
if (rect != ibuf->rect) {
|
|
|
|
|
MEM_freeN(rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scale_ibuf != NULL) {
|
|
|
|
|
IMB_freeImBuf(scale_ibuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
|
|
|
|
|
|
|
|
if (GPU_get_mipmap()) {
|
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
|
|
|
if (ima) {
|
|
|
|
|
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GLEW_EXT_texture_filter_anisotropic) {
|
|
|
|
|
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
|
|
|
|
|
|
|
|
|
|
return bindcode;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget)
|
|
|
|
|
{
|
|
|
|
|
uint bindcode = 0;
|
|
|
|
|
const bool mipmap = GPU_get_mipmap();
|
2016-05-05 11:25:31 +02:00
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
#ifdef WITH_DDS
|
|
|
|
|
if (ibuf->ftype == IMB_FTYPE_DDS) {
|
|
|
|
|
/* DDS is loaded directly in compressed form. */
|
2019-05-16 12:35:57 +02:00
|
|
|
GPU_create_gl_tex_compressed(&bindcode, textarget, ima, ibuf);
|
2019-04-23 13:56:30 +02:00
|
|
|
return bindcode;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Regular uncompressed texture. */
|
|
|
|
|
float *rect_float = ibuf->rect_float;
|
|
|
|
|
uchar *rect = (uchar *)ibuf->rect;
|
|
|
|
|
bool compress_as_srgb = false;
|
|
|
|
|
|
|
|
|
|
if (rect_float == NULL) {
|
|
|
|
|
/* Byte image is in original colorspace from the file. If the file is sRGB
|
|
|
|
|
* scene linear, or non-color data no conversion is needed. Otherwise we
|
|
|
|
|
* compress as scene linear + sRGB transfer function to avoid precision loss
|
|
|
|
|
* in common cases.
|
|
|
|
|
*
|
|
|
|
|
* We must also convert to premultiplied for correct texture interpolation
|
|
|
|
|
* and consistency with float images. */
|
|
|
|
|
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
|
|
|
|
compress_as_srgb = !IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace);
|
|
|
|
|
|
|
|
|
|
rect = MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__);
|
|
|
|
|
if (rect == NULL) {
|
|
|
|
|
return bindcode;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-07 17:49:58 +02:00
|
|
|
/* Texture storage of images is defined by the alpha mode of the image. The
|
|
|
|
|
* downside of this is that there can be artifacts near alpha edges. However,
|
|
|
|
|
* this allows us to use sRGB texture formats and preserves color values in
|
|
|
|
|
* zero alpha areas, and appears generally closer to what game engines that we
|
|
|
|
|
* want to be compatible with do. */
|
2019-04-02 16:05:22 +02:00
|
|
|
const bool store_premultiplied = ima ? (ima->alpha_mode == IMA_ALPHA_PREMUL) : true;
|
2019-06-07 17:49:58 +02:00
|
|
|
IMB_colormanagement_imbuf_to_byte_texture(
|
|
|
|
|
rect, 0, 0, ibuf->x, ibuf->y, ibuf, compress_as_srgb, store_premultiplied);
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-06-07 17:49:58 +02:00
|
|
|
else {
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Float image is already in scene linear colorspace or non-color data by
|
|
|
|
|
* convention, no colorspace conversion needed. But we do require 4 channels
|
|
|
|
|
* currently. */
|
2019-04-02 16:05:22 +02:00
|
|
|
const bool store_premultiplied = ima ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) : false;
|
2019-04-23 13:56:30 +02:00
|
|
|
|
2019-06-07 17:49:58 +02:00
|
|
|
if (ibuf->channels != 4 || !store_premultiplied) {
|
|
|
|
|
rect_float = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__);
|
|
|
|
|
if (rect_float == NULL) {
|
|
|
|
|
return bindcode;
|
|
|
|
|
}
|
|
|
|
|
IMB_colormanagement_imbuf_to_float_texture(
|
|
|
|
|
rect_float, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied);
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create OpenGL texture. */
|
|
|
|
|
GPU_create_gl_tex(&bindcode,
|
|
|
|
|
(uint *)rect,
|
|
|
|
|
rect_float,
|
|
|
|
|
ibuf->x,
|
|
|
|
|
ibuf->y,
|
|
|
|
|
textarget,
|
|
|
|
|
mipmap,
|
|
|
|
|
compress_as_srgb,
|
|
|
|
|
ima);
|
|
|
|
|
|
|
|
|
|
/* Free buffers if needed. */
|
|
|
|
|
if (rect && rect != (uchar *)ibuf->rect) {
|
|
|
|
|
MEM_freeN(rect);
|
|
|
|
|
}
|
|
|
|
|
if (rect_float && rect_float != ibuf->rect_float) {
|
|
|
|
|
MEM_freeN(rect_float);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bindcode;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-02 16:05:22 +02:00
|
|
|
static GPUTexture **gpu_get_movieclip_gputexture(MovieClip *clip,
|
|
|
|
|
MovieClipUser *cuser,
|
|
|
|
|
GLenum textarget)
|
|
|
|
|
{
|
|
|
|
|
MovieClip_RuntimeGPUTexture *tex;
|
|
|
|
|
for (tex = clip->runtime.gputextures.first; tex; tex = tex->next) {
|
|
|
|
|
if (memcmp(&tex->user, cuser, sizeof(MovieClipUser)) == 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tex == NULL) {
|
|
|
|
|
tex = MEM_mallocN(sizeof(MovieClip_RuntimeGPUTexture), __func__);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
|
|
|
|
tex->gputexture[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(&tex->user, cuser, sizeof(MovieClipUser));
|
|
|
|
|
BLI_addtail(&clip->runtime.gputextures, tex);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-22 23:06:02 +10:00
|
|
|
if (textarget == GL_TEXTURE_2D) {
|
2019-04-02 16:05:22 +02:00
|
|
|
return &tex->gputexture[TEXTARGET_TEXTURE_2D];
|
2019-06-22 23:06:02 +10:00
|
|
|
}
|
|
|
|
|
else if (textarget == GL_TEXTURE_CUBE_MAP) {
|
2019-04-02 16:05:22 +02:00
|
|
|
return &tex->gputexture[TEXTARGET_TEXTURE_CUBE_MAP];
|
2019-06-22 23:06:02 +10:00
|
|
|
}
|
2019-04-02 16:05:22 +02:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
static ImBuf *update_do_scale(uchar *rect,
|
|
|
|
|
float *rect_float,
|
|
|
|
|
int *x,
|
|
|
|
|
int *y,
|
|
|
|
|
int *w,
|
|
|
|
|
int *h,
|
|
|
|
|
int limit_w,
|
|
|
|
|
int limit_h,
|
|
|
|
|
int full_w,
|
|
|
|
|
int full_h)
|
2016-05-05 11:25:31 +02:00
|
|
|
{
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Partial update with scaling. */
|
|
|
|
|
float xratio = limit_w / (float)full_w;
|
|
|
|
|
float yratio = limit_h / (float)full_h;
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
int part_w = *w, part_h = *h;
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Find sub coordinates in scaled image. Take ceiling because we will be
|
|
|
|
|
* losing 1 pixel due to rounding errors in x,y. */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
*x *= xratio;
|
|
|
|
|
*y *= yratio;
|
|
|
|
|
*w = (int)ceil(xratio * (*w));
|
|
|
|
|
*h = (int)ceil(yratio * (*h));
|
2019-04-23 13:56:30 +02:00
|
|
|
|
|
|
|
|
/* ...but take back if we are over the limit! */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (*x + *w > limit_w) {
|
|
|
|
|
(*w)--;
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (*y + *h > limit_h) {
|
|
|
|
|
(*h)--;
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Scale pixels. */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
ImBuf *ibuf = IMB_allocFromBuffer((uint *)rect, rect_float, part_w, part_h, 4);
|
|
|
|
|
IMB_scaleImBuf(ibuf, *w, *h);
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_texture_update_scaled_array(uchar *rect,
|
|
|
|
|
float *rect_float,
|
|
|
|
|
int full_w,
|
|
|
|
|
int full_h,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
int layer,
|
|
|
|
|
const int *tile_offset,
|
|
|
|
|
const int *tile_size,
|
|
|
|
|
int w,
|
|
|
|
|
int h)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *ibuf = update_do_scale(
|
|
|
|
|
rect, rect_float, &x, &y, &w, &h, tile_size[0], tile_size[1], full_w, full_h);
|
|
|
|
|
|
|
|
|
|
/* Shift to account for tile packing. */
|
|
|
|
|
x += tile_offset[0];
|
|
|
|
|
y += tile_offset[1];
|
2019-04-23 13:56:30 +02:00
|
|
|
|
|
|
|
|
if (ibuf->rect_float) {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
glTexSubImage3D(
|
|
|
|
|
GL_TEXTURE_2D_ARRAY, 0, x, y, layer, w, h, 1, GL_RGBA, GL_FLOAT, ibuf->rect_float);
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
else {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
glTexSubImage3D(
|
|
|
|
|
GL_TEXTURE_2D_ARRAY, 0, x, y, layer, w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
2016-05-05 11:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
static void gpu_texture_update_scaled(
|
|
|
|
|
uchar *rect, float *rect_float, int full_w, int full_h, int x, int y, int w, int h)
|
|
|
|
|
{
|
|
|
|
|
/* Partial update with scaling. */
|
|
|
|
|
int limit_w = smaller_power_of_2_limit(full_w);
|
|
|
|
|
int limit_h = smaller_power_of_2_limit(full_h);
|
|
|
|
|
|
|
|
|
|
ImBuf *ibuf = update_do_scale(
|
|
|
|
|
rect, rect_float, &x, &y, &w, &h, limit_w, limit_h, full_w, full_h);
|
|
|
|
|
|
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_FLOAT, ibuf->rect_float);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_texture_update_unscaled(uchar *rect,
|
|
|
|
|
float *rect_float,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
int layer,
|
|
|
|
|
int w,
|
|
|
|
|
int h,
|
|
|
|
|
GLint tex_stride,
|
|
|
|
|
GLint tex_offset)
|
2016-05-05 11:25:31 +02:00
|
|
|
{
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Partial update without scaling. Stride and offset are used to copy only a
|
|
|
|
|
* subset of a possible larger buffer than what we are updating. */
|
|
|
|
|
GLint row_length;
|
|
|
|
|
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, tex_stride);
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (layer >= 0) {
|
|
|
|
|
if (rect_float == NULL) {
|
|
|
|
|
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
|
|
|
|
0,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
layer,
|
|
|
|
|
w,
|
|
|
|
|
h,
|
|
|
|
|
1,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
|
rect + tex_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
|
|
|
|
0,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
layer,
|
|
|
|
|
w,
|
|
|
|
|
h,
|
|
|
|
|
1,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_FLOAT,
|
|
|
|
|
rect_float + tex_offset);
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
else {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (rect_float == NULL) {
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect + tex_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_FLOAT, rect_float + tex_offset);
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
|
2016-05-05 11:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
static void gpu_texture_update_from_ibuf(
|
|
|
|
|
GPUTexture *tex, Image *ima, ImBuf *ibuf, ImageTile *tile, int x, int y, int w, int h)
|
2016-05-05 11:25:31 +02:00
|
|
|
{
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Partial update of texture for texture painting. This is often much
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
* quicker than fully updating the texture for high resolution images. */
|
|
|
|
|
GPU_texture_bind(tex, 0);
|
|
|
|
|
|
|
|
|
|
bool scaled;
|
|
|
|
|
if (tile != NULL) {
|
|
|
|
|
int *tilesize = tile->runtime.tilearray_size;
|
|
|
|
|
scaled = (ibuf->x != tilesize[0]) || (ibuf->y != tilesize[1]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
scaled = is_over_resolution_limit(GL_TEXTURE_2D, ibuf->x, ibuf->y);
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
|
|
|
|
|
if (scaled) {
|
|
|
|
|
/* Extra padding to account for bleed from neighboring pixels. */
|
|
|
|
|
const int padding = 4;
|
|
|
|
|
const int xmax = min_ii(x + w + padding, ibuf->x);
|
|
|
|
|
const int ymax = min_ii(y + h + padding, ibuf->y);
|
|
|
|
|
x = max_ii(x - padding, 0);
|
|
|
|
|
y = max_ii(y - padding, 0);
|
|
|
|
|
w = xmax - x;
|
|
|
|
|
h = ymax - y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get texture data pointers. */
|
|
|
|
|
float *rect_float = ibuf->rect_float;
|
|
|
|
|
uchar *rect = (uchar *)ibuf->rect;
|
|
|
|
|
GLint tex_stride = ibuf->x;
|
|
|
|
|
GLint tex_offset = ibuf->channels * (y * ibuf->x + x);
|
|
|
|
|
|
|
|
|
|
if (rect_float == NULL) {
|
|
|
|
|
/* Byte pixels. */
|
|
|
|
|
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
|
|
|
|
const bool compress_as_srgb = !IMB_colormanagement_space_is_scene_linear(
|
|
|
|
|
ibuf->rect_colorspace);
|
|
|
|
|
|
|
|
|
|
rect = MEM_mallocN(sizeof(uchar) * 4 * w * h, __func__);
|
|
|
|
|
if (rect == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tex_stride = w;
|
|
|
|
|
tex_offset = 0;
|
|
|
|
|
|
|
|
|
|
/* Convert to scene linear with sRGB compression, and premultiplied for
|
|
|
|
|
* correct texture interpolation. */
|
2019-06-07 17:49:58 +02:00
|
|
|
const bool store_premultiplied = (ima->alpha_mode == IMA_ALPHA_PREMUL);
|
|
|
|
|
IMB_colormanagement_imbuf_to_byte_texture(
|
|
|
|
|
rect, x, y, w, h, ibuf, compress_as_srgb, store_premultiplied);
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-06-07 17:49:58 +02:00
|
|
|
else {
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Float pixels. */
|
2019-06-07 17:49:58 +02:00
|
|
|
const bool store_premultiplied = (ima->alpha_mode != IMA_ALPHA_STRAIGHT);
|
2019-04-23 13:56:30 +02:00
|
|
|
|
2019-06-07 17:49:58 +02:00
|
|
|
if (ibuf->channels != 4 || scaled || !store_premultiplied) {
|
2019-06-09 22:03:01 +02:00
|
|
|
rect_float = MEM_mallocN(sizeof(float) * 4 * w * h, __func__);
|
2019-06-07 17:49:58 +02:00
|
|
|
if (rect_float == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
|
2019-06-07 17:49:58 +02:00
|
|
|
tex_stride = w;
|
|
|
|
|
tex_offset = 0;
|
|
|
|
|
|
|
|
|
|
IMB_colormanagement_imbuf_to_float_texture(
|
|
|
|
|
rect_float, x, y, w, h, ibuf, store_premultiplied);
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scaled) {
|
|
|
|
|
/* Slower update where we first have to scale the input pixels. */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (tile != NULL) {
|
|
|
|
|
int *tileoffset = tile->runtime.tilearray_offset;
|
|
|
|
|
int *tilesize = tile->runtime.tilearray_size;
|
|
|
|
|
int tilelayer = tile->runtime.tilearray_layer;
|
|
|
|
|
gpu_texture_update_scaled_array(
|
|
|
|
|
rect, rect_float, ibuf->x, ibuf->y, x, y, tilelayer, tileoffset, tilesize, w, h);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gpu_texture_update_scaled(rect, rect_float, ibuf->x, ibuf->y, x, y, w, h);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Fast update at same resolution. */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (tile != NULL) {
|
|
|
|
|
int *tileoffset = tile->runtime.tilearray_offset;
|
|
|
|
|
int tilelayer = tile->runtime.tilearray_layer;
|
|
|
|
|
gpu_texture_update_unscaled(rect,
|
|
|
|
|
rect_float,
|
|
|
|
|
x + tileoffset[0],
|
|
|
|
|
y + tileoffset[1],
|
|
|
|
|
tilelayer,
|
|
|
|
|
w,
|
|
|
|
|
h,
|
|
|
|
|
tex_stride,
|
|
|
|
|
tex_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gpu_texture_update_unscaled(rect, rect_float, x, y, -1, w, h, tex_stride, tex_offset);
|
|
|
|
|
}
|
2019-04-23 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free buffers if needed. */
|
|
|
|
|
if (rect && rect != (uchar *)ibuf->rect) {
|
|
|
|
|
MEM_freeN(rect);
|
|
|
|
|
}
|
|
|
|
|
if (rect_float && rect_float != ibuf->rect_float) {
|
|
|
|
|
MEM_freeN(rect_float);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
|
|
|
|
|
if (GPU_get_mipmap()) {
|
|
|
|
|
glGenerateMipmap((tile != NULL) ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPU_texture_unbind(tex);
|
2016-05-05 11:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 16:28:55 +01:00
|
|
|
/* Get the GPUTexture for a given `Image`.
|
|
|
|
|
*
|
|
|
|
|
* `iuser` and `ibuf` are mutual exclusive parameters. The caller can pass the `ibuf` when already
|
|
|
|
|
* available. It is also required when requesting the GPUTexture for a render result. */
|
|
|
|
|
GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, ImBuf *ibuf, int textarget)
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ima == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* currently, gpu refresh tagging is used by ima sequences */
|
|
|
|
|
if (ima->gpuflag & IMA_GPU_REFRESH) {
|
|
|
|
|
gpu_free_image_immediate(ima);
|
|
|
|
|
ima->gpuflag &= ~IMA_GPU_REFRESH;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 15:40:09 +02:00
|
|
|
/* Tag as in active use for garbage collector. */
|
|
|
|
|
BKE_image_tag_time(ima);
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Test if we already have a texture. */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
GPUTexture **tex = gpu_get_image_gputexture(ima, textarget);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (*tex) {
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we have a valid image. If not, we return a dummy
|
|
|
|
|
* texture with zero bindcode so we don't keep trying. */
|
|
|
|
|
uint bindcode = 0;
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
ImageTile *tile = BKE_image_get_tile(ima, 0);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
if (tile->ok == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*tex = GPU_texture_from_bindcode(textarget, bindcode);
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check if we have a valid image buffer */
|
2020-01-27 16:28:55 +01:00
|
|
|
ImBuf *ibuf_intern = ibuf;
|
|
|
|
|
if (ibuf_intern == NULL) {
|
|
|
|
|
ibuf_intern = BKE_image_acquire_ibuf(ima, iuser, NULL);
|
|
|
|
|
if (ibuf_intern == NULL) {
|
|
|
|
|
*tex = GPU_texture_from_bindcode(textarget, bindcode);
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if (textarget == GL_TEXTURE_2D_ARRAY) {
|
2020-01-27 16:28:55 +01:00
|
|
|
bindcode = gpu_texture_create_tile_array(ima, ibuf_intern);
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
}
|
|
|
|
|
else if (textarget == GL_TEXTURE_1D_ARRAY) {
|
|
|
|
|
bindcode = gpu_texture_create_tile_mapping(ima);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-01-27 16:28:55 +01:00
|
|
|
bindcode = gpu_texture_create_from_ibuf(ima, ibuf_intern, textarget);
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-01-27 16:28:55 +01:00
|
|
|
/* if `ibuf` was given, we don't own the `ibuf_intern` */
|
|
|
|
|
if (ibuf == NULL) {
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf_intern, NULL);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
*tex = GPU_texture_from_bindcode(textarget, bindcode);
|
2019-06-24 22:09:04 +10:00
|
|
|
|
2020-01-27 16:28:55 +01:00
|
|
|
GPU_texture_orig_size_set(*tex, ibuf_intern->x, ibuf_intern->y);
|
2019-06-24 22:09:04 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return *tex;
|
2012-06-30 04:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-02 16:05:22 +02:00
|
|
|
GPUTexture *GPU_texture_from_movieclip(MovieClip *clip, MovieClipUser *cuser, int textarget)
|
|
|
|
|
{
|
|
|
|
|
if (clip == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUTexture **tex = gpu_get_movieclip_gputexture(clip, cuser, textarget);
|
|
|
|
|
if (*tex) {
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check if we have a valid image buffer */
|
|
|
|
|
uint bindcode = 0;
|
|
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, cuser);
|
|
|
|
|
if (ibuf == NULL) {
|
|
|
|
|
*tex = GPU_texture_from_bindcode(textarget, bindcode);
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bindcode = gpu_texture_create_from_ibuf(NULL, ibuf, textarget);
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
|
|
|
|
|
*tex = GPU_texture_from_bindcode(textarget, bindcode);
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_free_texture_movieclip(struct MovieClip *clip)
|
|
|
|
|
{
|
|
|
|
|
/* number of gpu textures to keep around as cache
|
|
|
|
|
* We don't want to keep too many GPU textures for
|
|
|
|
|
* movie clips around, as they can be large.*/
|
|
|
|
|
const int MOVIECLIP_NUM_GPUTEXTURES = 1;
|
|
|
|
|
|
|
|
|
|
while (BLI_listbase_count(&clip->runtime.gputextures) > MOVIECLIP_NUM_GPUTEXTURES) {
|
|
|
|
|
MovieClip_RuntimeGPUTexture *tex = BLI_pophead(&clip->runtime.gputextures);
|
|
|
|
|
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
|
|
|
|
/* free glsl image binding */
|
|
|
|
|
if (tex->gputexture[i]) {
|
|
|
|
|
GPU_texture_free(tex->gputexture[i]);
|
|
|
|
|
tex->gputexture[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(tex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
static void **gpu_gen_cube_map(uint *rect, float *frect, int rectw, int recth)
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
{
|
2019-04-23 13:56:30 +02:00
|
|
|
size_t block_size = frect ? sizeof(float[4]) : sizeof(uchar[4]);
|
2019-04-17 06:17:24 +02:00
|
|
|
void **sides = NULL;
|
|
|
|
|
int h = recth / 2;
|
|
|
|
|
int w = rectw / 3;
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
if (w != h) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return sides;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* PosX, NegX, PosY, NegY, PosZ, NegZ */
|
|
|
|
|
sides = MEM_mallocN(sizeof(void *) * 6, "");
|
2019-04-22 09:32:37 +10:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sides[i] = MEM_mallocN(block_size * w * h, "");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* divide image into six parts */
|
|
|
|
|
/* ______________________
|
|
|
|
|
* | | | |
|
|
|
|
|
* | NegX | NegY | PosX |
|
|
|
|
|
* |______|______|______|
|
|
|
|
|
* | | | |
|
|
|
|
|
* | NegZ | PosZ | PosY |
|
|
|
|
|
* |______|______|______|
|
|
|
|
|
*/
|
2019-04-23 13:56:30 +02:00
|
|
|
if (frect) {
|
2019-04-17 06:17:24 +02:00
|
|
|
float(*frectb)[4] = (float(*)[4])frect;
|
|
|
|
|
float(**fsides)[4] = (float(**)[4])sides;
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < h; y++) {
|
|
|
|
|
for (int x = 0; x < w; x++) {
|
|
|
|
|
memcpy(&fsides[0][x * h + y], &frectb[(recth - y - 1) * rectw + 2 * w + x], block_size);
|
|
|
|
|
memcpy(&fsides[1][x * h + y], &frectb[(y + h) * rectw + w - 1 - x], block_size);
|
|
|
|
|
memcpy(
|
|
|
|
|
&fsides[3][y * w + x], &frectb[(recth - y - 1) * rectw + 2 * w - 1 - x], block_size);
|
|
|
|
|
memcpy(&fsides[5][y * w + x], &frectb[(h - y - 1) * rectw + w - 1 - x], block_size);
|
|
|
|
|
}
|
|
|
|
|
memcpy(&fsides[2][y * w], frectb[y * rectw + 2 * w], block_size * w);
|
|
|
|
|
memcpy(&fsides[4][y * w], frectb[y * rectw + w], block_size * w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
uint **isides = (uint **)sides;
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < h; y++) {
|
|
|
|
|
for (int x = 0; x < w; x++) {
|
|
|
|
|
isides[0][x * h + y] = rect[(recth - y - 1) * rectw + 2 * w + x];
|
|
|
|
|
isides[1][x * h + y] = rect[(y + h) * rectw + w - 1 - x];
|
|
|
|
|
isides[3][y * w + x] = rect[(recth - y - 1) * rectw + 2 * w - 1 - x];
|
|
|
|
|
isides[5][y * w + x] = rect[(h - y - 1) * rectw + w - 1 - x];
|
|
|
|
|
}
|
|
|
|
|
memcpy(&isides[2][y * w], &rect[y * rectw + 2 * w], block_size * w);
|
|
|
|
|
memcpy(&isides[4][y * w], &rect[y * rectw + w], block_size * w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sides;
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_del_cube_map(void **cube_map)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
2019-04-22 09:32:37 +10:00
|
|
|
if (cube_map == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(cube_map[i]);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(cube_map);
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
}
|
|
|
|
|
|
2013-01-22 11:18:41 +00:00
|
|
|
/* Image *ima can be NULL */
|
2019-04-17 06:17:24 +02:00
|
|
|
void GPU_create_gl_tex(uint *bind,
|
|
|
|
|
uint *rect,
|
|
|
|
|
float *frect,
|
|
|
|
|
int rectw,
|
|
|
|
|
int recth,
|
|
|
|
|
int textarget,
|
|
|
|
|
bool mipmap,
|
2019-04-23 13:56:30 +02:00
|
|
|
bool use_srgb,
|
2019-04-17 06:17:24 +02:00
|
|
|
Image *ima)
|
2012-06-30 04:34:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
|
|
|
|
|
if (textarget == GL_TEXTURE_2D && is_over_resolution_limit(textarget, rectw, recth)) {
|
|
|
|
|
int tpx = rectw;
|
|
|
|
|
int tpy = recth;
|
|
|
|
|
rectw = smaller_power_of_2_limit(rectw);
|
|
|
|
|
recth = smaller_power_of_2_limit(recth);
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
if (frect) {
|
2019-08-27 08:42:50 +02:00
|
|
|
ibuf = IMB_allocFromBuffer(NULL, frect, tpx, tpy, 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_scaleImBuf(ibuf, rectw, recth);
|
|
|
|
|
|
|
|
|
|
frect = ibuf->rect_float;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-08-27 08:42:50 +02:00
|
|
|
ibuf = IMB_allocFromBuffer(rect, NULL, tpx, tpy, 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_scaleImBuf(ibuf, rectw, recth);
|
|
|
|
|
|
|
|
|
|
rect = ibuf->rect;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create image */
|
|
|
|
|
glGenTextures(1, (GLuint *)bind);
|
|
|
|
|
glBindTexture(textarget, *bind);
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
GLenum internal_format = (frect) ? GL_RGBA16F : (use_srgb) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (textarget == GL_TEXTURE_2D) {
|
2019-04-23 13:56:30 +02:00
|
|
|
if (frect) {
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-23 13:56:30 +02:00
|
|
|
glTexImage2D(
|
|
|
|
|
GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
|
|
|
|
|
|
|
|
if (GPU_get_mipmap() && mipmap) {
|
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
2019-04-22 09:32:37 +10:00
|
|
|
if (ima) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (textarget == GL_TEXTURE_CUBE_MAP) {
|
|
|
|
|
int w = rectw / 3, h = recth / 2;
|
|
|
|
|
|
|
|
|
|
if (h == w && is_power_of_2_i(h) && !is_over_resolution_limit(textarget, h, w)) {
|
2019-04-23 13:56:30 +02:00
|
|
|
void **cube_map = gpu_gen_cube_map(rect, frect, rectw, recth);
|
|
|
|
|
GLenum type = frect ? GL_FLOAT : GL_UNSIGNED_BYTE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (cube_map) {
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
|
|
|
|
|
0,
|
2019-04-23 13:56:30 +02:00
|
|
|
internal_format,
|
2019-04-17 06:17:24 +02:00
|
|
|
w,
|
|
|
|
|
h,
|
|
|
|
|
0,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
type,
|
|
|
|
|
cube_map[i]);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
|
|
|
|
|
|
|
|
if (GPU_get_mipmap() && mipmap) {
|
|
|
|
|
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (ima) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
}
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
|
|
gpu_del_cube_map(cube_map);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("Incorrect envmap size\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (GLEW_EXT_texture_filter_anisotropic) {
|
2019-04-17 06:17:24 +02:00
|
|
|
glTexParameterf(textarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
glBindTexture(textarget, 0);
|
|
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(ibuf);
|
2019-04-22 09:32:37 +10: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
|
|
|
}
|
|
|
|
|
|
2012-06-30 04:34:34 +00:00
|
|
|
/**
|
|
|
|
|
* GPU_upload_dxt_texture() assumes that the texture is already bound and ready to go.
|
|
|
|
|
* This is so the viewport and the BGE can share some code.
|
2014-04-01 11:34:00 +11:00
|
|
|
* Returns false if the provided ImBuf doesn't have a supported DXT compression format
|
2012-06-30 04:34:34 +00:00
|
|
|
*/
|
2019-05-16 12:35:57 +02:00
|
|
|
bool GPU_upload_dxt_texture(ImBuf *ibuf, bool use_srgb)
|
2012-06-30 04:34:34 +00:00
|
|
|
{
|
2012-09-16 23:24:26 +00:00
|
|
|
#ifdef WITH_DDS
|
2019-04-17 06:17:24 +02:00
|
|
|
GLint format = 0;
|
|
|
|
|
int blocksize, height, width, i, size, offset = 0;
|
|
|
|
|
|
|
|
|
|
width = ibuf->x;
|
|
|
|
|
height = ibuf->y;
|
|
|
|
|
|
|
|
|
|
if (GLEW_EXT_texture_compression_s3tc) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (ibuf->dds_data.fourcc == FOURCC_DXT1) {
|
2019-05-16 12:35:57 +02:00
|
|
|
format = (use_srgb) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT :
|
|
|
|
|
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
else if (ibuf->dds_data.fourcc == FOURCC_DXT3) {
|
2019-05-16 12:35:57 +02:00
|
|
|
format = (use_srgb) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT :
|
|
|
|
|
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
else if (ibuf->dds_data.fourcc == FOURCC_DXT5) {
|
2019-05-16 12:35:57 +02:00
|
|
|
format = (use_srgb) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT :
|
|
|
|
|
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (format == 0) {
|
|
|
|
|
fprintf(stderr, "Unable to find a suitable DXT compression, falling back to uncompressed\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_power_of_2_resolution(width, height)) {
|
|
|
|
|
fprintf(
|
|
|
|
|
stderr,
|
|
|
|
|
"Unable to load non-power-of-two DXT image resolution, falling back to uncompressed\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (GLEW_EXT_texture_filter_anisotropic) {
|
2019-04-17 06:17:24 +02:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
blocksize = (ibuf->dds_data.fourcc == FOURCC_DXT1) ? 8 : 16;
|
2019-09-08 00:12:26 +10:00
|
|
|
for (i = 0; i < ibuf->dds_data.nummipmaps && (width || height); i++) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (width == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
width = 1;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
|
if (height == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
height = 1;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
size = ((width + 3) / 4) * ((height + 3) / 4) * blocksize;
|
|
|
|
|
|
|
|
|
|
glCompressedTexImage2D(
|
|
|
|
|
GL_TEXTURE_2D, i, format, width, height, 0, size, ibuf->dds_data.data + offset);
|
|
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
|
width >>= 1;
|
|
|
|
|
height >>= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set number of mipmap levels we have, needed in case they don't go down to 1x1 */
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, i - 1);
|
|
|
|
|
|
|
|
|
|
return true;
|
2012-06-30 10:31:25 +00:00
|
|
|
#else
|
2019-05-16 21:16:56 +10:00
|
|
|
UNUSED_VARS(ibuf, use_srgb);
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2012-06-30 10:31:25 +00:00
|
|
|
#endif
|
2012-06-30 04:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 12:35:57 +02:00
|
|
|
void GPU_create_gl_tex_compressed(unsigned int *bind, int textarget, Image *ima, ImBuf *ibuf)
|
2012-06-30 04:34:34 +00:00
|
|
|
{
|
2019-05-16 12:35:57 +02:00
|
|
|
/* For DDS we only support data, scene linear and sRGB. Converting to
|
|
|
|
|
* different colorspace would break the compression. */
|
|
|
|
|
const bool use_srgb = !(IMB_colormanagement_space_is_data(ibuf->rect_colorspace) ||
|
|
|
|
|
IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace));
|
|
|
|
|
const bool mipmap = GPU_get_mipmap();
|
|
|
|
|
|
2012-06-30 04:34:34 +00:00
|
|
|
#ifndef WITH_DDS
|
2019-04-17 06:17:24 +02:00
|
|
|
(void)ibuf;
|
|
|
|
|
/* Fall back to uncompressed if DDS isn't enabled */
|
2019-05-16 12:35:57 +02:00
|
|
|
GPU_create_gl_tex(bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, use_srgb, ima);
|
2012-06-30 04:34:34 +00:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
glGenTextures(1, (GLuint *)bind);
|
|
|
|
|
glBindTexture(textarget, *bind);
|
2012-06-30 04:34:34 +00:00
|
|
|
|
2019-05-16 12:35:57 +02:00
|
|
|
if (textarget == GL_TEXTURE_2D && GPU_upload_dxt_texture(ibuf, use_srgb) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
glDeleteTextures(1, (GLuint *)bind);
|
2019-05-21 13:00:43 +02:00
|
|
|
GPU_create_gl_tex(bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, use_srgb, ima);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-11 22:30:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glBindTexture(textarget, 0);
|
2012-06-30 04:34:34 +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
|
|
|
|
|
|
|
|
/* these two functions are called on entering and exiting texture paint mode,
|
2012-03-09 18:28:30 +00:00
|
|
|
* temporary disabling/enabling mipmapping on all images for quick texture
|
|
|
|
|
* updates with glTexSubImage2D. images that didn't change don't have to be
|
|
|
|
|
* re-uploaded to OpenGL */
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_paint_set_mipmap(Main *bmain, bool 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
|
|
|
{
|
2019-04-22 09:32:37 +10:00
|
|
|
if (!GTS.domipmap) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
GTS.texpaint = !mipmap;
|
|
|
|
|
|
|
|
|
|
if (mipmap) {
|
|
|
|
|
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
|
|
|
|
|
if (BKE_image_has_opengl_texture(ima)) {
|
|
|
|
|
if (ima->gpuflag & IMA_GPU_MIPMAP_COMPLETE) {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
for (int a = 0; a < TEXTARGET_COUNT; a++) {
|
|
|
|
|
if (ELEM(a, TEXTARGET_TEXTURE_2D, TEXTARGET_TEXTURE_2D_ARRAY)) {
|
|
|
|
|
GPUTexture *tex = ima->gputexture[a];
|
|
|
|
|
if (tex != NULL) {
|
|
|
|
|
GPU_texture_bind(tex, 0);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
}
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_free_image(ima);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
|
|
|
|
|
if (BKE_image_has_opengl_texture(ima)) {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
for (int a = 0; a < TEXTARGET_COUNT; a++) {
|
|
|
|
|
if (ELEM(a, TEXTARGET_TEXTURE_2D, TEXTARGET_TEXTURE_2D_ARRAY)) {
|
|
|
|
|
GPUTexture *tex = ima->gputexture[a];
|
|
|
|
|
if (tex != NULL) {
|
|
|
|
|
GPU_texture_bind(tex, 0);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
}
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +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
|
|
|
}
|
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, int 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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
if ((ibuf == NULL) || (w == 0) || (h == 0)) {
|
2019-04-23 13:56:30 +02:00
|
|
|
/* Full reload of texture. */
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_free_image(ima);
|
|
|
|
|
}
|
|
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
GPUTexture *tex = ima->gputexture[TEXTARGET_TEXTURE_2D];
|
|
|
|
|
/* Check if we need to update the main gputexture. */
|
|
|
|
|
if (tex != NULL && tile == ima->tiles.first) {
|
|
|
|
|
gpu_texture_update_from_ibuf(tex, ima, ibuf, NULL, x, y, w, h);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
/* Check if we need to update the array gputexture. */
|
|
|
|
|
tex = ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY];
|
|
|
|
|
if (tex != NULL) {
|
|
|
|
|
gpu_texture_update_from_ibuf(tex, ima, ibuf, tile, x, y, w, h);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, 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
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:01:16 +00:00
|
|
|
static LinkNode *image_free_queue = NULL;
|
2019-04-23 20:34:26 +02:00
|
|
|
static ThreadMutex img_queue_mutex = BLI_MUTEX_INITIALIZER;
|
2010-04-13 20:34:40 +00:00
|
|
|
|
2010-04-25 10:49:13 +00:00
|
|
|
static void gpu_queue_image_for_free(Image *ima)
|
2010-04-13 12:51:03 +00:00
|
|
|
{
|
2019-04-23 20:34:26 +02:00
|
|
|
BLI_mutex_lock(&img_queue_mutex);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_linklist_prepend(&image_free_queue, ima);
|
2019-04-23 20:34:26 +02:00
|
|
|
BLI_mutex_unlock(&img_queue_mutex);
|
2010-04-13 12:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_free_unused_buffers(Main *bmain)
|
2010-04-13 12:51:03 +00:00
|
|
|
{
|
2019-04-22 09:32:37 +10:00
|
|
|
if (!BLI_thread_is_main()) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2010-05-05 17:14:43 +00:00
|
|
|
|
2019-04-23 20:34:26 +02:00
|
|
|
BLI_mutex_lock(&img_queue_mutex);
|
2010-04-25 10:49:13 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* images */
|
|
|
|
|
for (LinkNode *node = image_free_queue; node; node = node->next) {
|
|
|
|
|
Image *ima = node->link;
|
2013-06-15 14:01:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* check in case it was freed in the meantime */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (bmain && BLI_findindex(&bmain->images, ima) != -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_free_image(ima);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-25 10:49:13 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_linklist_free(image_free_queue, NULL);
|
|
|
|
|
image_free_queue = NULL;
|
2010-04-25 10:49:13 +00:00
|
|
|
|
2019-04-23 20:34:26 +02:00
|
|
|
BLI_mutex_unlock(&img_queue_mutex);
|
2010-04-13 12:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-18 13:23:49 +01:00
|
|
|
static void gpu_free_image_immediate(Image *ima)
|
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
|
|
|
{
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
|
|
|
|
/* free glsl image binding */
|
|
|
|
|
if (ima->gputexture[i] != NULL) {
|
|
|
|
|
GPU_texture_free(ima->gputexture[i]);
|
|
|
|
|
ima->gputexture[i] = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 13:56:30 +02:00
|
|
|
ima->gpuflag &= ~(IMA_GPU_MIPMAP_COMPLETE);
|
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
|
|
|
}
|
|
|
|
|
|
2019-02-18 13:23:49 +01:00
|
|
|
void GPU_free_image(Image *ima)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!BLI_thread_is_main()) {
|
|
|
|
|
gpu_queue_image_for_free(ima);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-18 13:23:49 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
gpu_free_image_immediate(ima);
|
2019-02-18 13:23:49 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_free_images(Main *bmain)
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (bmain) {
|
|
|
|
|
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
|
|
|
|
|
GPU_free_image(ima);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-20 16:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* same as above but only free animated images */
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_free_images_anim(Main *bmain)
|
2010-05-20 16:08:06 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (bmain) {
|
|
|
|
|
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
|
|
|
|
|
if (BKE_image_is_animated(ima)) {
|
|
|
|
|
GPU_free_image(ima);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_free_images_old(Main *bmain)
|
2014-05-22 11:58:07 +10:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
static int lasttime = 0;
|
|
|
|
|
int ctime = (int)PIL_check_seconds_timer();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Run garbage collector once for every collecting period of time
|
|
|
|
|
* if textimeout is 0, that's the option to NOT run the collector
|
|
|
|
|
*/
|
2019-04-22 09:32:37 +10:00
|
|
|
if (U.textimeout == 0 || ctime % U.texcollectrate || ctime == lasttime) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* of course not! */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (G.is_rendering) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
lasttime = ctime;
|
|
|
|
|
|
|
|
|
|
Image *ima = bmain->images.first;
|
|
|
|
|
while (ima) {
|
|
|
|
|
if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) {
|
|
|
|
|
/* If it's in GL memory, deallocate and set time tag to current time
|
|
|
|
|
* This gives textures a "second chance" to be used before dying. */
|
|
|
|
|
if (BKE_image_has_opengl_texture(ima)) {
|
|
|
|
|
GPU_free_image(ima);
|
|
|
|
|
ima->lastused = ctime;
|
|
|
|
|
}
|
|
|
|
|
/* Otherwise, just kill the buffers */
|
|
|
|
|
else {
|
|
|
|
|
BKE_image_free_buffers(ima);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ima = ima->id.next;
|
|
|
|
|
}
|
2014-05-22 11:58:07 +10:00
|
|
|
}
|
|
|
|
|
|
2018-02-15 18:03:55 +11:00
|
|
|
static void gpu_disable_multisample(void)
|
2014-10-07 15:46:19 -05:00
|
|
|
{
|
|
|
|
|
#ifdef __linux__
|
2019-04-17 06:17:24 +02:00
|
|
|
/* changing multisample from the default (enabled) causes problems on some
|
|
|
|
|
* systems (NVIDIA/Linux) when the pixel format doesn't have a multisample buffer */
|
|
|
|
|
bool toggle_ok = true;
|
2014-10-07 15:46:19 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_UNIX, GPU_DRIVER_ANY)) {
|
|
|
|
|
int samples = 0;
|
|
|
|
|
glGetIntegerv(GL_SAMPLES, &samples);
|
2014-10-07 15:46:19 -05:00
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (samples == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
toggle_ok = false;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-10-07 15:46:19 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (toggle_ok) {
|
|
|
|
|
glDisable(GL_MULTISAMPLE);
|
|
|
|
|
}
|
2015-11-24 02:20:38 -05:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
glDisable(GL_MULTISAMPLE);
|
2015-11-24 02:20:38 -05:00
|
|
|
#endif
|
2014-10-07 15:46:19 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-28 01:09:13 +01:00
|
|
|
/* Default OpenGL State
|
|
|
|
|
*
|
2018-04-16 14:07:42 +02:00
|
|
|
* This is called on startup, for opengl offscreen render.
|
|
|
|
|
* Generally we should always return to this state when
|
2015-11-28 01:09:13 +01:00
|
|
|
* temporarily modifying the state for drawing, though that are (undocumented)
|
|
|
|
|
* exceptions that we should try to get rid of. */
|
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_state_init(void)
|
|
|
|
|
{
|
2019-05-28 17:14:22 +02:00
|
|
|
GPU_program_point_size(false);
|
2016-10-01 17:34:41 -04:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
2016-09-30 19:51:04 -04:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glDepthFunc(GL_LEQUAL);
|
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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
glDisable(GL_COLOR_LOGIC_OP);
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
2017-04-27 14:32:47 -04:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glDepthRange(0.0, 1.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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glFrontFace(GL_CCW);
|
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
2010-01-08 09:30:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
gpu_disable_multisample();
|
2019-05-29 00:08:10 +02:00
|
|
|
|
|
|
|
|
/* This is a bit dangerous since addons could change this. */
|
|
|
|
|
glEnable(GL_PRIMITIVE_RESTART);
|
|
|
|
|
glPrimitiveRestartIndex((GLuint)0xFFFFFFFF);
|
|
|
|
|
|
|
|
|
|
/* TODO: Should become default. But needs at least GL 4.3 */
|
|
|
|
|
if (GLEW_ARB_ES3_compatibility) {
|
|
|
|
|
/* Takes predecence over GL_PRIMITIVE_RESTART */
|
|
|
|
|
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2016-06-25 20:16:33 +10:00
|
|
|
/** \name Framebuffer color depth, for selection codes
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2017-05-09 15:09:39 +02:00
|
|
|
#define STATE_STACK_DEPTH 16
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2019-04-17 06:17:24 +02:00
|
|
|
eGPUAttrMask mask;
|
|
|
|
|
|
|
|
|
|
/* GL_ENABLE_BIT */
|
|
|
|
|
uint is_blend : 1;
|
|
|
|
|
uint is_cull_face : 1;
|
|
|
|
|
uint is_depth_test : 1;
|
|
|
|
|
uint is_dither : 1;
|
|
|
|
|
uint is_lighting : 1;
|
|
|
|
|
uint is_line_smooth : 1;
|
|
|
|
|
uint is_color_logic_op : 1;
|
|
|
|
|
uint is_multisample : 1;
|
|
|
|
|
uint is_polygon_offset_line : 1;
|
|
|
|
|
uint is_polygon_offset_fill : 1;
|
|
|
|
|
uint is_polygon_smooth : 1;
|
|
|
|
|
uint is_sample_alpha_to_coverage : 1;
|
|
|
|
|
uint is_scissor_test : 1;
|
|
|
|
|
uint is_stencil_test : 1;
|
|
|
|
|
|
|
|
|
|
bool is_clip_plane[6];
|
|
|
|
|
|
|
|
|
|
/* GL_DEPTH_BUFFER_BIT */
|
|
|
|
|
/* uint is_depth_test : 1; */
|
|
|
|
|
int depth_func;
|
|
|
|
|
double depth_clear_value;
|
|
|
|
|
bool depth_write_mask;
|
|
|
|
|
|
|
|
|
|
/* GL_SCISSOR_BIT */
|
|
|
|
|
int scissor_box[4];
|
|
|
|
|
/* uint is_scissor_test : 1; */
|
|
|
|
|
|
|
|
|
|
/* GL_VIEWPORT_BIT */
|
|
|
|
|
int viewport[4];
|
|
|
|
|
double near_far[2];
|
|
|
|
|
} GPUAttrValues;
|
2017-05-09 15:09:39 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUAttrValues attr_stack[STATE_STACK_DEPTH];
|
|
|
|
|
uint top;
|
2019-01-29 07:46:25 +11:00
|
|
|
} GPUAttrStack;
|
2017-05-09 15:09:39 +02:00
|
|
|
|
2019-01-29 07:46:25 +11:00
|
|
|
static GPUAttrStack state = {
|
2019-04-17 06:17:24 +02:00
|
|
|
.top = 0,
|
2017-05-09 15:09:39 +02:00
|
|
|
};
|
|
|
|
|
|
2019-01-29 07:46:25 +11:00
|
|
|
#define AttrStack state
|
|
|
|
|
#define Attr state.attr_stack[state.top]
|
2017-05-09 15:09:39 +02:00
|
|
|
|
2017-04-04 20:33:23 +02:00
|
|
|
/**
|
|
|
|
|
* Replacement for glPush/PopAttributes
|
|
|
|
|
*
|
|
|
|
|
* We don't need to cover all the options of legacy OpenGL
|
|
|
|
|
* but simply the ones used by Blender.
|
|
|
|
|
*/
|
2019-01-29 07:46:25 +11:00
|
|
|
void gpuPushAttr(eGPUAttrMask mask)
|
2017-04-04 20:33:23 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Attr.mask = mask;
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
|
|
|
|
|
Attr.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
|
|
|
|
glGetIntegerv(GL_DEPTH_FUNC, &Attr.depth_func);
|
|
|
|
|
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &Attr.depth_clear_value);
|
|
|
|
|
glGetBooleanv(GL_DEPTH_WRITEMASK, (GLboolean *)&Attr.depth_write_mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_ENABLE_BIT) != 0) {
|
|
|
|
|
Attr.is_blend = glIsEnabled(GL_BLEND);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
Attr.is_clip_plane[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Attr.is_cull_face = glIsEnabled(GL_CULL_FACE);
|
|
|
|
|
Attr.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
|
|
|
|
Attr.is_dither = glIsEnabled(GL_DITHER);
|
|
|
|
|
Attr.is_line_smooth = glIsEnabled(GL_LINE_SMOOTH);
|
|
|
|
|
Attr.is_color_logic_op = glIsEnabled(GL_COLOR_LOGIC_OP);
|
|
|
|
|
Attr.is_multisample = glIsEnabled(GL_MULTISAMPLE);
|
|
|
|
|
Attr.is_polygon_offset_line = glIsEnabled(GL_POLYGON_OFFSET_LINE);
|
|
|
|
|
Attr.is_polygon_offset_fill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
|
|
|
|
|
Attr.is_polygon_smooth = glIsEnabled(GL_POLYGON_SMOOTH);
|
|
|
|
|
Attr.is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
|
|
|
|
|
Attr.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
|
|
|
|
Attr.is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_SCISSOR_BIT) != 0) {
|
|
|
|
|
Attr.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
|
|
|
|
glGetIntegerv(GL_SCISSOR_BOX, (GLint *)&Attr.scissor_box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_VIEWPORT_BIT) != 0) {
|
|
|
|
|
glGetDoublev(GL_DEPTH_RANGE, (GLdouble *)&Attr.near_far);
|
|
|
|
|
glGetIntegerv(GL_VIEWPORT, (GLint *)&Attr.viewport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_BLEND_BIT) != 0) {
|
|
|
|
|
Attr.is_blend = glIsEnabled(GL_BLEND);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert(AttrStack.top < STATE_STACK_DEPTH);
|
|
|
|
|
AttrStack.top++;
|
2017-04-04 20:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-07 15:57:14 +11:00
|
|
|
static void restore_mask(GLenum cap, const bool value)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (value) {
|
|
|
|
|
glEnable(cap);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glDisable(cap);
|
|
|
|
|
}
|
2017-04-04 20:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-29 07:46:25 +11:00
|
|
|
void gpuPopAttr(void)
|
2017-04-04 20:33:23 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(AttrStack.top > 0);
|
|
|
|
|
AttrStack.top--;
|
|
|
|
|
|
|
|
|
|
GLint mask = Attr.mask;
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
|
|
|
|
|
restore_mask(GL_DEPTH_TEST, Attr.is_depth_test);
|
|
|
|
|
glDepthFunc(Attr.depth_func);
|
|
|
|
|
glClearDepth(Attr.depth_clear_value);
|
|
|
|
|
glDepthMask(Attr.depth_write_mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_ENABLE_BIT) != 0) {
|
|
|
|
|
restore_mask(GL_BLEND, Attr.is_blend);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
restore_mask(GL_CLIP_PLANE0 + i, Attr.is_clip_plane[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_mask(GL_CULL_FACE, Attr.is_cull_face);
|
|
|
|
|
restore_mask(GL_DEPTH_TEST, Attr.is_depth_test);
|
|
|
|
|
restore_mask(GL_DITHER, Attr.is_dither);
|
|
|
|
|
restore_mask(GL_LINE_SMOOTH, Attr.is_line_smooth);
|
|
|
|
|
restore_mask(GL_COLOR_LOGIC_OP, Attr.is_color_logic_op);
|
|
|
|
|
restore_mask(GL_MULTISAMPLE, Attr.is_multisample);
|
|
|
|
|
restore_mask(GL_POLYGON_OFFSET_LINE, Attr.is_polygon_offset_line);
|
|
|
|
|
restore_mask(GL_POLYGON_OFFSET_FILL, Attr.is_polygon_offset_fill);
|
|
|
|
|
restore_mask(GL_POLYGON_SMOOTH, Attr.is_polygon_smooth);
|
|
|
|
|
restore_mask(GL_SAMPLE_ALPHA_TO_COVERAGE, Attr.is_sample_alpha_to_coverage);
|
|
|
|
|
restore_mask(GL_SCISSOR_TEST, Attr.is_scissor_test);
|
|
|
|
|
restore_mask(GL_STENCIL_TEST, Attr.is_stencil_test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_VIEWPORT_BIT) != 0) {
|
|
|
|
|
glViewport(Attr.viewport[0], Attr.viewport[1], Attr.viewport[2], Attr.viewport[3]);
|
|
|
|
|
glDepthRange(Attr.near_far[0], Attr.near_far[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_SCISSOR_BIT) != 0) {
|
|
|
|
|
restore_mask(GL_SCISSOR_TEST, Attr.is_scissor_test);
|
|
|
|
|
glScissor(Attr.scissor_box[0], Attr.scissor_box[1], Attr.scissor_box[2], Attr.scissor_box[3]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((mask & GPU_BLEND_BIT) != 0) {
|
|
|
|
|
restore_mask(GL_BLEND, Attr.is_blend);
|
|
|
|
|
}
|
2017-04-04 20:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-29 07:46:25 +11:00
|
|
|
#undef Attr
|
|
|
|
|
#undef AttrStack
|
2017-05-09 15:09:39 +02:00
|
|
|
|
2016-06-25 20:16:33 +10:00
|
|
|
/** \} */
|