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
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
* about this.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Brecht Van Lommel.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GL/glew.h"
|
|
|
|
|
|
|
|
#include "DNA_image_types.h"
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
2008-09-20 13:02:06 +00:00
|
|
|
#include "BKE_utildefines.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 "BLI_blenlib.h"
|
|
|
|
|
|
|
|
#include "GPU_draw.h"
|
|
|
|
#include "GPU_extensions.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* Extensions support */
|
|
|
|
|
|
|
|
/* extensions used:
|
|
|
|
- texture border clamp: 1.3 core
|
|
|
|
- fragement shader: 2.0 core
|
|
|
|
- framebuffer object: ext specification
|
|
|
|
- multitexture 1.3 core
|
|
|
|
- arb non power of two: 2.0 core
|
|
|
|
- pixel buffer objects? 2.1 core
|
|
|
|
- arb draw buffers? 2.0 core
|
|
|
|
*/
|
|
|
|
|
2008-10-12 18:32:26 +00:00
|
|
|
static struct GPUGlobal {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GLint maxtextures;
|
|
|
|
GLuint currentfb;
|
2009-10-19 10:10:05 +00:00
|
|
|
int glslsupport;
|
2008-10-12 18:32:26 +00:00
|
|
|
int extdisabled;
|
2010-07-04 12:24:19 +00:00
|
|
|
int colordepth;
|
2010-11-27 19:59:00 +00:00
|
|
|
int npotdisabled; /* ATI 3xx-5xx (and more) chipsets support NPoT partially (== not enough) */
|
2010-01-31 23:45:51 +00:00
|
|
|
GPUDeviceType device;
|
|
|
|
GPUOSType os;
|
|
|
|
GPUDriverType driver;
|
2010-11-25 22:15:04 +00:00
|
|
|
} GG = {1, 0, 0, 0, 0};
|
2008-10-12 18:32:26 +00:00
|
|
|
|
2010-01-31 23:45:51 +00:00
|
|
|
/* GPU Types */
|
|
|
|
|
|
|
|
int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
|
|
|
|
{
|
|
|
|
return (GG.device & device) && (GG.os & os) && (GG.driver & driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPU Extensions */
|
|
|
|
|
2008-10-12 18:32:26 +00:00
|
|
|
void GPU_extensions_disable()
|
|
|
|
{
|
|
|
|
GG.extdisabled = 1;
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
void GPU_extensions_init()
|
|
|
|
{
|
2010-07-04 12:24:19 +00:00
|
|
|
GLint r, g, b;
|
2010-01-31 23:45:51 +00:00
|
|
|
const char *vendor, *renderer;
|
|
|
|
|
2010-11-27 19:59:00 +00:00
|
|
|
/* can't avoid calling this multiple times, see wm_window_add_ghostwindow */
|
2010-10-22 00:29:56 +00:00
|
|
|
static char init= 0;
|
|
|
|
if(init) return;
|
|
|
|
init= 1;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glewInit();
|
|
|
|
|
|
|
|
/* glewIsSupported("GL_VERSION_2_0") */
|
|
|
|
|
|
|
|
if (GLEW_ARB_multitexture)
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures);
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
GG.glslsupport = 1;
|
|
|
|
if (!GLEW_ARB_multitexture) GG.glslsupport = 0;
|
|
|
|
if (!GLEW_ARB_vertex_shader) GG.glslsupport = 0;
|
|
|
|
if (!GLEW_ARB_fragment_shader) GG.glslsupport = 0;
|
2010-01-31 23:45:51 +00:00
|
|
|
|
2010-07-04 12:24:19 +00:00
|
|
|
glGetIntegerv(GL_RED_BITS, &r);
|
|
|
|
glGetIntegerv(GL_GREEN_BITS, &g);
|
|
|
|
glGetIntegerv(GL_BLUE_BITS, &b);
|
|
|
|
GG.colordepth = r+g+b; /* assumes same depth for RGB */
|
|
|
|
|
2010-01-31 23:45:51 +00:00
|
|
|
vendor = (const char*)glGetString(GL_VENDOR);
|
|
|
|
renderer = (const char*)glGetString(GL_RENDERER);
|
|
|
|
|
|
|
|
if(strstr(vendor, "ATI")) {
|
|
|
|
GG.device = GPU_DEVICE_ATI;
|
|
|
|
GG.driver = GPU_DRIVER_OFFICIAL;
|
2010-11-25 22:15:04 +00:00
|
|
|
|
|
|
|
/* ATI X1xxx cards (R500 chipset) lack full support for npot textures
|
|
|
|
* although they report the GLEW_ARB_texture_non_power_of_two extension.
|
|
|
|
*/
|
|
|
|
if(strstr(renderer, "X1"))
|
|
|
|
GG.npotdisabled = 1;
|
2010-01-31 23:45:51 +00:00
|
|
|
}
|
|
|
|
else if(strstr(vendor, "NVIDIA")) {
|
|
|
|
GG.device = GPU_DEVICE_NVIDIA;
|
|
|
|
GG.driver = GPU_DRIVER_OFFICIAL;
|
|
|
|
}
|
2010-04-14 21:12:05 +00:00
|
|
|
else if(strstr(vendor, "Intel") ||
|
|
|
|
/* src/mesa/drivers/dri/intel/intel_context.c */
|
|
|
|
strstr(renderer, "Mesa DRI Intel") ||
|
|
|
|
strstr(renderer, "Mesa DRI Mobile Intel")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_INTEL;
|
|
|
|
GG.driver = GPU_DRIVER_OFFICIAL;
|
|
|
|
}
|
2010-11-27 19:59:00 +00:00
|
|
|
else if(strstr(renderer, "Mesa DRI R") || (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI "))) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_ATI;
|
|
|
|
GG.driver = GPU_DRIVER_OPENSOURCE;
|
2010-11-27 19:59:00 +00:00
|
|
|
/* ATI 9500 to X2300 cards support NPoT textures poorly
|
|
|
|
* Incomplete list http://dri.freedesktop.org/wiki/ATIRadeon
|
|
|
|
* New IDs from MESA's src/gallium/drivers/r300/r300_screen.c
|
|
|
|
*/
|
|
|
|
if(strstr(renderer, "R3") || strstr(renderer, "RV3") ||
|
|
|
|
strstr(renderer, "R4") || strstr(renderer, "RV4") ||
|
|
|
|
strstr(renderer, "RS4") || strstr(renderer, "RC4") ||
|
|
|
|
strstr(renderer, "R5") || strstr(renderer, "RV5") ||
|
|
|
|
strstr(renderer, "RS600") || strstr(renderer, "RS690") ||
|
|
|
|
strstr(renderer, "RS740"))
|
|
|
|
GG.npotdisabled = 1;
|
2010-01-31 23:45:51 +00:00
|
|
|
}
|
2010-10-22 01:06:21 +00:00
|
|
|
else if(strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_NVIDIA;
|
|
|
|
GG.driver = GPU_DRIVER_OPENSOURCE;
|
|
|
|
}
|
2010-02-01 10:04:37 +00:00
|
|
|
else if(strstr(vendor, "Mesa")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_SOFTWARE;
|
|
|
|
GG.driver = GPU_DRIVER_SOFTWARE;
|
|
|
|
}
|
|
|
|
else if(strstr(vendor, "Microsoft")) {
|
|
|
|
GG.device = GPU_DEVICE_SOFTWARE;
|
|
|
|
GG.driver = GPU_DRIVER_SOFTWARE;
|
|
|
|
}
|
2010-02-01 10:04:37 +00:00
|
|
|
else if(strstr(renderer, "Apple Software Renderer")) {
|
2010-01-31 23:45:51 +00:00
|
|
|
GG.device = GPU_DEVICE_SOFTWARE;
|
|
|
|
GG.driver = GPU_DRIVER_SOFTWARE;
|
|
|
|
}
|
|
|
|
else {
|
2010-07-16 10:13:04 +00:00
|
|
|
GG.device = GPU_DEVICE_ANY;
|
|
|
|
GG.driver = GPU_DRIVER_ANY;
|
2010-01-31 23:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GG.os = GPU_OS_UNIX;
|
|
|
|
#ifdef _WIN32
|
|
|
|
GG.os = GPU_OS_WIN;
|
|
|
|
#endif
|
|
|
|
#ifdef __APPLE__
|
|
|
|
GG.os = GPU_OS_MAC;
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
int GPU_glsl_support()
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2009-10-19 10:10:05 +00:00
|
|
|
return !GG.extdisabled && GG.glslsupport;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_non_power_of_two_support()
|
|
|
|
{
|
|
|
|
/* Exception for buggy ATI/Apple driver in Mac OS X 10.5/10.6,
|
|
|
|
* they claim to support this but can cause system freeze */
|
2010-01-31 23:45:51 +00:00
|
|
|
if(GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_MAC, GPU_DRIVER_OFFICIAL))
|
2009-10-19 10:10:05 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-11-25 22:15:04 +00:00
|
|
|
if(GG.npotdisabled)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
return GLEW_ARB_texture_non_power_of_two;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2010-07-04 12:24:19 +00:00
|
|
|
int GPU_color_depth()
|
2010-04-05 10:25:40 +00:00
|
|
|
{
|
2010-07-04 12:24:19 +00:00
|
|
|
return GG.colordepth;
|
2010-04-05 10:25:40 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
int GPU_print_error(const char *str)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GLenum errCode;
|
|
|
|
|
|
|
|
if (G.f & G_DEBUG) {
|
|
|
|
if ((errCode = glGetError()) != GL_NO_ERROR) {
|
2010-03-22 09:30:00 +00:00
|
|
|
fprintf(stderr, "%s opengl error: %s\n", str, gluErrorString(errCode));
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GPU_print_framebuffer_error(GLenum status)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "GPUFrameBuffer: framebuffer incomplete error %d\n",
|
|
|
|
(int)status);
|
|
|
|
|
|
|
|
switch(status) {
|
|
|
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
|
|
|
|
fprintf(stderr, "Incomplete attachment.\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
|
|
|
|
fprintf(stderr, "Unsupported framebuffer format.\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
|
|
|
|
fprintf(stderr, "Missing attachment.\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
|
|
|
|
fprintf(stderr, "Attached images must have same dimensions.\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
|
|
|
|
fprintf(stderr, "Attached images must have same format.\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
|
|
|
|
fprintf(stderr, "Missing draw buffer.\n");
|
|
|
|
break;
|
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
|
|
|
|
fprintf(stderr, "Missing read buffer.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unknown.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPUTexture */
|
|
|
|
|
|
|
|
struct GPUTexture {
|
|
|
|
int w, h; /* width/height */
|
|
|
|
int number; /* number for multitexture binding */
|
|
|
|
int refcount; /* reference count */
|
|
|
|
GLenum target; /* GL_TEXTURE_* */
|
|
|
|
GLuint bindcode; /* opengl identifier for texture */
|
|
|
|
int fromblender; /* we got the texture from Blender */
|
|
|
|
|
|
|
|
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
|
|
|
|
int depth; /* is a depth texture? */
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels)
|
|
|
|
{
|
|
|
|
unsigned char *pixels, *p;
|
|
|
|
float *fp;
|
|
|
|
int a, len;
|
|
|
|
|
|
|
|
len = 4*length;
|
|
|
|
fp = fpixels;
|
|
|
|
p = pixels = MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels");
|
|
|
|
|
|
|
|
for (a=0; a<len; a++, p++, fp++)
|
|
|
|
*p = FTOCHAR((*fp));
|
|
|
|
|
|
|
|
return pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_pow2(int n)
|
|
|
|
{
|
|
|
|
return ((n)&(n-1))==0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int larger_pow2(int n)
|
|
|
|
{
|
|
|
|
if (is_pow2(n))
|
|
|
|
return n;
|
|
|
|
|
|
|
|
while(!is_pow2(n))
|
|
|
|
n= n&(n-1);
|
|
|
|
|
|
|
|
return n*2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
void *pixels = MEM_callocN(sizeof(char)*4*w*h, "GPUTextureEmptyPixels");
|
|
|
|
|
|
|
|
if (target == GL_TEXTURE_1D)
|
|
|
|
glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(target, 0, x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, int depth)
|
|
|
|
{
|
|
|
|
GPUTexture *tex;
|
|
|
|
GLenum type, format, internalformat;
|
|
|
|
void *pixels = NULL;
|
|
|
|
|
|
|
|
if(depth && !GLEW_ARB_depth_texture)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
|
|
|
tex->w = w;
|
|
|
|
tex->h = h;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = (n == 1)? GL_TEXTURE_1D: GL_TEXTURE_2D;
|
|
|
|
tex->depth = depth;
|
|
|
|
|
|
|
|
glGenTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
if (!tex->bindcode) {
|
|
|
|
fprintf(stderr, "GPUTexture: texture create failed: %d\n",
|
|
|
|
(int)glGetError());
|
|
|
|
GPU_texture_free(tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
if (!GPU_non_power_of_two_support()) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
tex->w = larger_pow2(tex->w);
|
|
|
|
tex->h = larger_pow2(tex->h);
|
|
|
|
}
|
|
|
|
|
|
|
|
tex->number = 0;
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
|
|
|
|
if(depth) {
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
format = GL_DEPTH_COMPONENT;
|
|
|
|
internalformat = GL_DEPTH_COMPONENT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
format = GL_RGBA;
|
|
|
|
internalformat = GL_RGBA8;
|
|
|
|
|
|
|
|
if (fpixels)
|
|
|
|
pixels = GPU_texture_convert_pixels(w*h, fpixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->target == GL_TEXTURE_1D) {
|
|
|
|
glTexImage1D(tex->target, 0, internalformat, tex->w, 0, format, type, 0);
|
|
|
|
|
|
|
|
if (fpixels) {
|
|
|
|
glTexSubImage1D(tex->target, 0, 0, w, format, type,
|
|
|
|
pixels? pixels: fpixels);
|
|
|
|
|
|
|
|
if (tex->w > w)
|
|
|
|
GPU_glTexSubImageEmpty(tex->target, format, w, 0,
|
|
|
|
tex->w-w, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0,
|
|
|
|
format, type, 0);
|
|
|
|
|
|
|
|
if (fpixels) {
|
|
|
|
glTexSubImage2D(tex->target, 0, 0, 0, w, h,
|
|
|
|
format, type, pixels? pixels: fpixels);
|
|
|
|
|
|
|
|
if (tex->w > w)
|
|
|
|
GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h);
|
|
|
|
if (tex->h > h)
|
|
|
|
GPU_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h-h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixels)
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
|
|
|
|
if(depth) {
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
|
|
|
glTexParameteri(tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->target != GL_TEXTURE_1D) {
|
|
|
|
/* CLAMP_TO_BORDER is an OpenGL 1.3 core feature */
|
|
|
|
GLenum wrapmode = (depth)? GL_CLAMP_TO_EDGE: GL_CLAMP_TO_BORDER;
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_WRAP_S, wrapmode);
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_WRAP_T, wrapmode);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glTexParameteri(tex->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2009-08-20 00:33:59 +00:00
|
|
|
|
|
|
|
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
|
|
|
|
{
|
|
|
|
GPUTexture *tex;
|
|
|
|
GLenum type, format, internalformat;
|
|
|
|
void *pixels = NULL;
|
2009-08-24 21:16:23 +00:00
|
|
|
float vfBorderColor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
2009-08-20 00:33:59 +00:00
|
|
|
|
2010-03-27 10:48:01 +00:00
|
|
|
if(!GLEW_VERSION_1_2)
|
|
|
|
return NULL;
|
|
|
|
|
2009-08-20 00:33:59 +00:00
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
|
|
|
tex->w = w;
|
|
|
|
tex->h = h;
|
|
|
|
tex->depth = depth;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = GL_TEXTURE_3D;
|
|
|
|
|
|
|
|
glGenTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
if (!tex->bindcode) {
|
|
|
|
fprintf(stderr, "GPUTexture: texture create failed: %d\n",
|
|
|
|
(int)glGetError());
|
|
|
|
GPU_texture_free(tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-19 10:10:05 +00:00
|
|
|
if (!GPU_non_power_of_two_support()) {
|
2009-08-20 00:33:59 +00:00
|
|
|
tex->w = larger_pow2(tex->w);
|
|
|
|
tex->h = larger_pow2(tex->h);
|
|
|
|
tex->depth = larger_pow2(tex->depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
tex->number = 0;
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
|
2009-09-15 10:26:36 +00:00
|
|
|
GPU_print_error("3D glBindTexture");
|
|
|
|
|
2009-09-09 18:39:40 +00:00
|
|
|
type = GL_FLOAT; // GL_UNSIGNED_BYTE
|
|
|
|
format = GL_RED;
|
2009-09-14 22:27:10 +00:00
|
|
|
internalformat = GL_INTENSITY;
|
2009-08-20 00:33:59 +00:00
|
|
|
|
2009-09-09 18:39:40 +00:00
|
|
|
//if (fpixels)
|
|
|
|
// pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
|
2009-08-20 00:33:59 +00:00
|
|
|
|
|
|
|
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, 0);
|
|
|
|
|
2009-09-15 10:26:36 +00:00
|
|
|
GPU_print_error("3D glTexImage3D");
|
|
|
|
|
2009-08-20 00:33:59 +00:00
|
|
|
if (fpixels) {
|
2010-01-30 09:24:50 +00:00
|
|
|
if(!GPU_non_power_of_two_support() && (w != tex->w || h != tex->h || depth != tex->depth)) {
|
|
|
|
/* clear first to avoid unitialized pixels */
|
|
|
|
float *zero= MEM_callocN(sizeof(float)*tex->w*tex->h*tex->depth, "zero");
|
|
|
|
glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, tex->h, tex->depth, format, type, zero);
|
|
|
|
MEM_freeN(zero);
|
|
|
|
}
|
|
|
|
|
2009-09-09 18:39:40 +00:00
|
|
|
glTexSubImage3D(tex->target, 0, 0, 0, 0, w, h, depth, format, type, fpixels);
|
2009-09-15 10:26:36 +00:00
|
|
|
GPU_print_error("3D glTexSubImage3D");
|
2009-08-20 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 10:26:36 +00:00
|
|
|
|
2009-08-24 21:39:48 +00:00
|
|
|
glTexParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, vfBorderColor);
|
2009-09-15 10:26:36 +00:00
|
|
|
GPU_print_error("3D GL_TEXTURE_BORDER_COLOR");
|
2009-08-20 00:33:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2009-09-15 10:26:36 +00:00
|
|
|
GPU_print_error("3D GL_LINEAR");
|
2009-10-20 15:51:25 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
2009-09-15 10:26:36 +00:00
|
|
|
GPU_print_error("3D GL_CLAMP_TO_BORDER");
|
2009-08-20 00:33:59 +00:00
|
|
|
|
|
|
|
if (pixels)
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2009-08-16 20:14:49 +00:00
|
|
|
GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GPUTexture *tex;
|
|
|
|
GLint w, h, border, lastbindcode, bindcode;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
|
|
|
|
|
|
|
|
GPU_update_image_time(ima, time);
|
2010-10-15 12:29:02 +00:00
|
|
|
bindcode = GPU_verify_image(ima, iuser, 0, 0, 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
|
|
|
|
|
|
|
if(ima->gputexture) {
|
|
|
|
ima->gputexture->bindcode = bindcode;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
return ima->gputexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bindcode) {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
|
|
|
tex->bindcode = bindcode;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = GL_TEXTURE_2D;
|
|
|
|
tex->fromblender = 1;
|
|
|
|
|
|
|
|
ima->gputexture= tex;
|
|
|
|
|
|
|
|
if (!glIsTexture(tex->bindcode)) {
|
|
|
|
GPU_print_error("Blender Texture");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->bindcode);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, &border);
|
|
|
|
|
|
|
|
tex->w = w - border;
|
|
|
|
tex->h = h - border;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, lastbindcode);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUTexture *GPU_texture_create_1D(int w, float *fpixels)
|
|
|
|
{
|
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, 1, 1, fpixels, 0);
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUTexture *GPU_texture_create_2D(int w, int h, float *fpixels)
|
|
|
|
{
|
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0);
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUTexture *GPU_texture_create_depth(int w, int h)
|
|
|
|
{
|
|
|
|
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1);
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_bind(GPUTexture *tex, int number)
|
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (number >= GG.maxtextures) {
|
|
|
|
GPU_print_error("Not enough texture slots.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(number == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GPU_print_error("Pre Texture Bind");
|
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + number);
|
|
|
|
if (number != 0) glActiveTextureARB(arbnumber);
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
glEnable(tex->target);
|
|
|
|
if (number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
|
|
|
tex->number = number;
|
|
|
|
|
|
|
|
GPU_print_error("Post Texture Bind");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_unbind(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (tex->number >= GG.maxtextures) {
|
|
|
|
GPU_print_error("Not enough texture slots.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GPU_print_error("Pre Texture Unbind");
|
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(arbnumber);
|
|
|
|
glBindTexture(tex->target, 0);
|
|
|
|
glDisable(tex->target);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
|
|
|
tex->number = -1;
|
|
|
|
|
|
|
|
GPU_print_error("Post Texture Unbind");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_free(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
tex->refcount--;
|
|
|
|
|
|
|
|
if (tex->refcount < 0)
|
|
|
|
fprintf(stderr, "GPUTexture: negative refcount\n");
|
|
|
|
|
|
|
|
if (tex->refcount == 0) {
|
|
|
|
if (tex->fb)
|
|
|
|
GPU_framebuffer_texture_detach(tex->fb, tex);
|
|
|
|
if (tex->bindcode && !tex->fromblender)
|
|
|
|
glDeleteTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
MEM_freeN(tex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_ref(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
tex->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_target(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_opengl_width(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_opengl_height(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->h;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPUFrameBuffer */
|
|
|
|
|
|
|
|
struct GPUFrameBuffer {
|
|
|
|
GLuint object;
|
|
|
|
GPUTexture *colortex;
|
|
|
|
GPUTexture *depthtex;
|
|
|
|
};
|
|
|
|
|
|
|
|
GPUFrameBuffer *GPU_framebuffer_create()
|
|
|
|
{
|
|
|
|
GPUFrameBuffer *fb;
|
|
|
|
|
|
|
|
if (!GLEW_EXT_framebuffer_object)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
|
|
|
|
glGenFramebuffersEXT(1, &fb->object);
|
|
|
|
|
|
|
|
if (!fb->object) {
|
|
|
|
fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n",
|
|
|
|
(int)glGetError());
|
|
|
|
GPU_framebuffer_free(fb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex)
|
|
|
|
{
|
|
|
|
GLenum status;
|
|
|
|
GLenum attachment;
|
|
|
|
|
|
|
|
if(tex->depth)
|
|
|
|
attachment = GL_DEPTH_ATTACHMENT_EXT;
|
|
|
|
else
|
|
|
|
attachment = GL_COLOR_ATTACHMENT0_EXT;
|
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
|
|
|
|
GG.currentfb = fb->object;
|
|
|
|
|
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
|
|
|
|
tex->target, tex->bindcode, 0);
|
|
|
|
|
|
|
|
if(tex->depth) {
|
|
|
|
glDrawBuffer(GL_NONE);
|
|
|
|
glReadBuffer(GL_NONE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
2009-10-28 18:03:04 +00:00
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
|
|
|
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
GPU_print_framebuffer_error(status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tex->depth)
|
|
|
|
fb->depthtex = tex;
|
|
|
|
else
|
|
|
|
fb->colortex = tex;
|
|
|
|
|
|
|
|
tex->fb= fb;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
|
|
|
|
{
|
|
|
|
GLenum attachment;
|
|
|
|
|
|
|
|
if(!tex->fb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(GG.currentfb != tex->fb->object) {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
|
|
|
|
GG.currentfb = tex->fb->object;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tex->depth) {
|
|
|
|
fb->depthtex = NULL;
|
|
|
|
attachment = GL_DEPTH_ATTACHMENT_EXT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fb->colortex = NULL;
|
|
|
|
attachment = GL_COLOR_ATTACHMENT0_EXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
|
|
|
|
tex->target, 0, 0);
|
|
|
|
|
|
|
|
tex->fb = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
/* push attributes */
|
|
|
|
glPushAttrib(GL_ENABLE_BIT);
|
|
|
|
glPushAttrib(GL_VIEWPORT_BIT);
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
/* bind framebuffer */
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
|
|
|
|
|
|
|
|
/* push matrices and set default viewport and matrix */
|
|
|
|
glViewport(0, 0, tex->w, tex->h);
|
|
|
|
GG.currentfb = tex->fb->object;
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex))
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
/* restore matrix */
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
/* restore attributes */
|
|
|
|
glPopAttrib();
|
|
|
|
glPopAttrib();
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_framebuffer_free(GPUFrameBuffer *fb)
|
|
|
|
{
|
|
|
|
if(fb->depthtex)
|
|
|
|
GPU_framebuffer_texture_detach(fb, fb->depthtex);
|
|
|
|
if(fb->colortex)
|
|
|
|
GPU_framebuffer_texture_detach(fb, fb->colortex);
|
|
|
|
|
|
|
|
if(fb->object) {
|
|
|
|
glDeleteFramebuffersEXT(1, &fb->object);
|
|
|
|
|
|
|
|
if (GG.currentfb == fb->object) {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
GG.currentfb = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_framebuffer_restore()
|
|
|
|
{
|
|
|
|
if (GG.currentfb != 0) {
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
GG.currentfb = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:03:04 +00:00
|
|
|
/* GPUOffScreen */
|
|
|
|
|
|
|
|
struct GPUOffScreen {
|
|
|
|
GPUFrameBuffer *fb;
|
|
|
|
GPUTexture *color;
|
|
|
|
GPUTexture *depth;
|
|
|
|
};
|
|
|
|
|
2010-11-18 19:11:05 +00:00
|
|
|
GPUOffScreen *GPU_offscreen_create(int *width, int *height)
|
2009-10-28 18:03:04 +00:00
|
|
|
{
|
|
|
|
GPUOffScreen *ofs;
|
|
|
|
|
|
|
|
ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
|
|
|
|
|
|
|
|
ofs->fb = GPU_framebuffer_create();
|
|
|
|
if(!ofs->fb) {
|
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-18 19:11:05 +00:00
|
|
|
ofs->depth = GPU_texture_create_depth(*width, *height);
|
2009-10-28 18:03:04 +00:00
|
|
|
if(!ofs->depth) {
|
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-18 19:11:05 +00:00
|
|
|
if(*width!=ofs->depth->w || *height!=ofs->depth->h) {
|
|
|
|
*width= ofs->depth->w;
|
|
|
|
*height= ofs->depth->h;
|
|
|
|
printf("Offscreen size differs from given size!\n");
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:03:04 +00:00
|
|
|
if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth)) {
|
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-18 19:11:05 +00:00
|
|
|
ofs->color = GPU_texture_create_2D(*width, *height, NULL);
|
2009-10-28 18:03:04 +00:00
|
|
|
if(!ofs->color) {
|
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->color)) {
|
|
|
|
GPU_offscreen_free(ofs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
|
|
|
|
return ofs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_offscreen_free(GPUOffScreen *ofs)
|
|
|
|
{
|
|
|
|
if(ofs->fb)
|
|
|
|
GPU_framebuffer_free(ofs->fb);
|
|
|
|
if(ofs->color)
|
|
|
|
GPU_texture_free(ofs->color);
|
|
|
|
if(ofs->depth)
|
|
|
|
GPU_texture_free(ofs->depth);
|
|
|
|
|
|
|
|
MEM_freeN(ofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_offscreen_bind(GPUOffScreen *ofs)
|
|
|
|
{
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
GPU_framebuffer_texture_bind(ofs->fb, ofs->color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_offscreen_unbind(GPUOffScreen *ofs)
|
|
|
|
{
|
|
|
|
GPU_framebuffer_texture_unbind(ofs->fb, ofs->color);
|
|
|
|
GPU_framebuffer_restore();
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* GPUShader */
|
|
|
|
|
|
|
|
struct GPUShader {
|
|
|
|
GLhandleARB object; /* handle for full shader */
|
|
|
|
GLhandleARB vertex; /* handle for vertex shader */
|
|
|
|
GLhandleARB fragment; /* handle for fragment shader */
|
|
|
|
GLhandleARB lib; /* handle for libment shader */
|
|
|
|
int totattrib; /* total number of attributes */
|
|
|
|
};
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
static void shader_print_errors(const char *task, char *log, const char *code)
|
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
|
|
|
{
|
|
|
|
const char *c, *pos, *end = code + strlen(code);
|
|
|
|
int line = 1;
|
|
|
|
|
|
|
|
fprintf(stderr, "GPUShader: %s error:\n", task);
|
|
|
|
|
|
|
|
if(G.f & G_DEBUG) {
|
|
|
|
c = code;
|
|
|
|
while ((c < end) && (pos = strchr(c, '\n'))) {
|
|
|
|
fprintf(stderr, "%2d ", line);
|
|
|
|
fwrite(c, (pos+1)-c, 1, stderr);
|
|
|
|
c = pos+1;
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%s", c);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%s\n", log);
|
|
|
|
}
|
|
|
|
|
2008-09-19 16:09:26 +00:00
|
|
|
GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPUShader *lib,*/ const char *libcode)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GLint status;
|
|
|
|
GLcharARB log[5000];
|
2008-09-19 16:09:26 +00:00
|
|
|
const char *fragsource[2];
|
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
|
|
|
GLsizei length = 0;
|
2008-09-19 16:09:26 +00:00
|
|
|
GLint count;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPUShader *shader;
|
|
|
|
|
|
|
|
if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
|
|
|
|
|
|
|
|
if(vertexcode)
|
|
|
|
shader->vertex = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
|
|
|
|
if(fragcode)
|
|
|
|
shader->fragment = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
|
|
|
|
shader->object = glCreateProgramObjectARB();
|
|
|
|
|
|
|
|
if (!shader->object ||
|
|
|
|
(vertexcode && !shader->vertex) ||
|
|
|
|
(fragcode && !shader->fragment)) {
|
|
|
|
fprintf(stderr, "GPUShader, object creation failed.\n");
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vertexcode) {
|
|
|
|
glAttachObjectARB(shader->object, shader->vertex);
|
|
|
|
glShaderSourceARB(shader->vertex, 1, (const char**)&vertexcode, NULL);
|
|
|
|
|
|
|
|
glCompileShaderARB(shader->vertex);
|
|
|
|
glGetObjectParameterivARB(shader->vertex, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->vertex, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("compile", log, vertexcode);
|
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fragcode) {
|
2008-09-19 16:09:26 +00:00
|
|
|
count = 0;
|
|
|
|
if(libcode) fragsource[count++] = libcode;
|
|
|
|
if(fragcode) fragsource[count++] = fragcode;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glAttachObjectARB(shader->object, shader->fragment);
|
2008-09-19 16:09:26 +00:00
|
|
|
glShaderSourceARB(shader->fragment, count, fragsource, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glCompileShaderARB(shader->fragment);
|
|
|
|
glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->fragment, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("compile", log, fragcode);
|
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-19 16:09:26 +00:00
|
|
|
/*if(lib && lib->lib)
|
|
|
|
glAttachObjectARB(shader->object, lib->lib);*/
|
2008-09-15 18:15:11 +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
|
|
|
glLinkProgramARB(shader->object);
|
|
|
|
glGetObjectParameterivARB(shader->object, GL_OBJECT_LINK_STATUS_ARB, &status);
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->object, sizeof(log), &length, log);
|
2009-06-14 06:52:46 +00:00
|
|
|
if (fragcode) shader_print_errors("linking", log, fragcode);
|
2009-06-13 22:31:14 +00:00
|
|
|
else if (vertexcode) shader_print_errors("linking", log, vertexcode);
|
|
|
|
else if (libcode) shader_print_errors("linking", log, libcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2008-09-19 16:09:26 +00:00
|
|
|
#if 0
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPUShader *GPU_shader_create_lib(const char *code)
|
|
|
|
{
|
|
|
|
GLint status;
|
|
|
|
GLcharARB log[5000];
|
|
|
|
GLsizei length = 0;
|
|
|
|
GPUShader *shader;
|
|
|
|
|
|
|
|
if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
|
|
|
|
|
|
|
|
shader->lib = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
|
|
|
|
|
|
|
|
if (!shader->lib) {
|
|
|
|
fprintf(stderr, "GPUShader, object creation failed.\n");
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
glShaderSourceARB(shader->lib, 1, (const char**)&code, NULL);
|
|
|
|
|
|
|
|
glCompileShaderARB(shader->lib);
|
|
|
|
glGetObjectParameterivARB(shader->lib, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
glGetInfoLogARB(shader->lib, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("compile", log, code);
|
|
|
|
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
2008-09-19 16:09:26 +00:00
|
|
|
#endif
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
void GPU_shader_bind(GPUShader *shader)
|
|
|
|
{
|
|
|
|
GPU_print_error("Pre Shader Bind");
|
|
|
|
glUseProgramObjectARB(shader->object);
|
|
|
|
GPU_print_error("Post Shader Bind");
|
|
|
|
}
|
|
|
|
|
2010-12-03 12:30:59 +00:00
|
|
|
void GPU_shader_unbind(GPUShader *UNUSED(shader))
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GPU_print_error("Pre Shader Unbind");
|
|
|
|
glUseProgramObjectARB(0);
|
|
|
|
GPU_print_error("Post Shader Unbind");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_shader_free(GPUShader *shader)
|
|
|
|
{
|
|
|
|
if (shader->lib)
|
|
|
|
glDeleteObjectARB(shader->lib);
|
|
|
|
if (shader->vertex)
|
|
|
|
glDeleteObjectARB(shader->vertex);
|
|
|
|
if (shader->fragment)
|
|
|
|
glDeleteObjectARB(shader->fragment);
|
|
|
|
if (shader->object)
|
|
|
|
glDeleteObjectARB(shader->object);
|
|
|
|
MEM_freeN(shader);
|
|
|
|
}
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
return glGetUniformLocationARB(shader->object, name);
|
|
|
|
}
|
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, float *value)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
if(location == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GPU_print_error("Pre Uniform Vector");
|
|
|
|
|
|
|
|
if (length == 1) glUniform1fvARB(location, arraysize, value);
|
|
|
|
else if (length == 2) glUniform2fvARB(location, arraysize, value);
|
|
|
|
else if (length == 3) glUniform3fvARB(location, arraysize, value);
|
|
|
|
else if (length == 4) glUniform4fvARB(location, arraysize, value);
|
|
|
|
else if (length == 9) glUniformMatrix3fvARB(location, arraysize, 0, value);
|
|
|
|
else if (length == 16) glUniformMatrix4fvARB(location, arraysize, 0, value);
|
|
|
|
|
|
|
|
GPU_print_error("Post Uniform Vector");
|
|
|
|
}
|
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
|
|
|
GLenum arbnumber;
|
|
|
|
|
|
|
|
if (tex->number >= GG.maxtextures) {
|
|
|
|
GPU_print_error("Not enough texture slots.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(location == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GPU_print_error("Pre Uniform Texture");
|
|
|
|
|
|
|
|
arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number);
|
|
|
|
|
|
|
|
if (tex->number != 0) glActiveTextureARB(arbnumber);
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
glUniform1iARB(location, tex->number);
|
|
|
|
glEnable(tex->target);
|
|
|
|
if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
|
|
|
GPU_print_error("Post Uniform Texture");
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_shader_get_attribute(GPUShader *shader, char *name)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
GPU_print_error("Pre Get Attribute");
|
|
|
|
|
|
|
|
index = glGetAttribLocationARB(shader->object, name);
|
|
|
|
|
|
|
|
GPU_print_error("Post Get Attribute");
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* GPUPixelBuffer */
|
|
|
|
|
|
|
|
typedef struct GPUPixelBuffer {
|
|
|
|
GLuint bindcode[2];
|
|
|
|
GLuint current;
|
|
|
|
int datasize;
|
|
|
|
int numbuffers;
|
|
|
|
int halffloat;
|
|
|
|
} GPUPixelBuffer;
|
|
|
|
|
|
|
|
void GPU_pixelbuffer_free(GPUPixelBuffer *pb)
|
|
|
|
{
|
|
|
|
if (pb->bindcode[0])
|
|
|
|
glDeleteBuffersARB(pb->numbuffers, pb->bindcode);
|
|
|
|
MEM_freeN(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUPixelBuffer *gpu_pixelbuffer_create(int x, int y, int halffloat, int numbuffers)
|
|
|
|
{
|
|
|
|
GPUPixelBuffer *pb;
|
|
|
|
|
|
|
|
if (!GLEW_ARB_multitexture || !GLEW_EXT_pixel_buffer_object)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pb = MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO");
|
|
|
|
pb->datasize = x*y*4*((halffloat)? 16: 8);
|
|
|
|
pb->numbuffers = numbuffers;
|
|
|
|
pb->halffloat = halffloat;
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glGenBuffersARB(pb->numbuffers, pb->bindcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
if (!pb->bindcode[0]) {
|
|
|
|
fprintf(stderr, "GPUPixelBuffer allocation failed\n");
|
|
|
|
GPU_pixelbuffer_free(pb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pixelbuffer_texture(GPUTexture *tex, GPUPixelBuffer *pb)
|
|
|
|
{
|
|
|
|
void *pixels;
|
|
|
|
int i;
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
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-03-22 09:30:00 +00:00
|
|
|
for (i = 0; i < pb->numbuffers; i++) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb->bindcode[pb->current]);
|
|
|
|
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb->datasize, NULL,
|
|
|
|
GL_STREAM_DRAW_ARB);
|
|
|
|
|
|
|
|
pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
|
|
|
|
/*memcpy(pixels, _oImage.data(), pb->datasize);*/
|
|
|
|
|
|
|
|
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
|
|
|
|
fprintf(stderr, "Could not unmap opengl PBO\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pixelbuffer_map_into_gpu(GLuint bindcode)
|
|
|
|
{
|
|
|
|
void *pixels;
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
|
|
|
|
|
|
|
|
/* do stuff in pixels */
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
fprintf(stderr, "Could not unmap opengl PBO\n");
|
|
|
|
return 0;
|
2010-03-22 09:30:00 +00:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pixelbuffer_copy_to_texture(GPUTexture *tex, GPUPixelBuffer *pb, GLuint bindcode)
|
|
|
|
{
|
|
|
|
GLenum type = (pb->halffloat)? GL_HALF_FLOAT_NV: GL_UNSIGNED_BYTE;
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h,
|
|
|
|
GL_RGBA, type, NULL);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
|
2010-03-22 09:30:00 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb)
|
|
|
|
{
|
|
|
|
int newbuffer;
|
|
|
|
|
|
|
|
if (pb->numbuffers == 1) {
|
|
|
|
pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[0]);
|
|
|
|
pixelbuffer_map_into_gpu(pb->bindcode[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pb->current = (pb->current+1)%pb->numbuffers;
|
|
|
|
newbuffer = (pb->current+1)%pb->numbuffers;
|
|
|
|
|
|
|
|
pixelbuffer_map_into_gpu(pb->bindcode[newbuffer]);
|
|
|
|
pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[pb->current]);
|
2010-03-22 09:30:00 +00:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|