svn merge -r 16351:16368 https://svn.blender.org/svnroot/bf-blender/trunk/blender
This commit is contained in:
@@ -90,6 +90,7 @@ IF(UNIX)
|
||||
bf_soundsystem
|
||||
bf_kernel
|
||||
bf_nodes
|
||||
bf_gpu
|
||||
bf_imbuf
|
||||
bf_avi
|
||||
kx_network
|
||||
|
||||
@@ -143,7 +143,6 @@ BF_FTGL_LIB = 'extern_ftgl'
|
||||
|
||||
WITH_BF_GAMEENGINE='true'
|
||||
WITH_BF_PLAYER='true'
|
||||
WITH_BF_GLEXT= '1'
|
||||
|
||||
WITH_BF_ODE = 'false'
|
||||
BF_ODE = LIBDIR + '/ode'
|
||||
|
||||
2
extern/glew/SConscript
vendored
2
extern/glew/SConscript
vendored
@@ -9,4 +9,4 @@ sources = ['src/glew.c']
|
||||
defs = ''
|
||||
incs = 'include'
|
||||
|
||||
env.BlenderLib ( 'extern_glew', sources, Split(incs), Split(defs), libtype=['intern', 'player'], priority=[25, 50])
|
||||
env.BlenderLib ( 'extern_glew', sources, Split(incs), Split(defs), libtype=['blender', 'player'], priority=[50, 50])
|
||||
|
||||
7
extern/glew/include/GL/glew.h
vendored
7
extern/glew/include/GL/glew.h
vendored
@@ -58,8 +58,11 @@
|
||||
** version 1.2.1 Specification.
|
||||
*/
|
||||
|
||||
/* added this here for blender, should be moved elsewhere */
|
||||
#define BLENDER_CHANGES
|
||||
|
||||
#ifdef BLENDER_CHANGES
|
||||
#define GLEW_STATIC
|
||||
#endif
|
||||
|
||||
#ifndef __glew_h__
|
||||
#define __glew_h__
|
||||
@@ -1805,6 +1808,7 @@ typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuin
|
||||
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort* v);
|
||||
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
|
||||
|
||||
#ifndef BLENDER_CHANGES
|
||||
#define glAttachShader GLEW_GET_FUN(__glewAttachShader)
|
||||
#define glBindAttribLocation GLEW_GET_FUN(__glewBindAttribLocation)
|
||||
#define glBlendEquationSeparate GLEW_GET_FUN(__glewBlendEquationSeparate)
|
||||
@@ -1898,6 +1902,7 @@ typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint si
|
||||
#define glVertexAttrib4uiv GLEW_GET_FUN(__glewVertexAttrib4uiv)
|
||||
#define glVertexAttrib4usv GLEW_GET_FUN(__glewVertexAttrib4usv)
|
||||
#define glVertexAttribPointer GLEW_GET_FUN(__glewVertexAttribPointer)
|
||||
#endif
|
||||
|
||||
#define GLEW_VERSION_2_0 GLEW_GET_VAR(__GLEW_VERSION_2_0)
|
||||
|
||||
|
||||
2
extern/glew/src/glew.c
vendored
2
extern/glew/src/glew.c
vendored
@@ -1836,6 +1836,7 @@ static GLboolean _glewInit_GL_VERSION_2_0 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||
{
|
||||
GLboolean r = GL_FALSE;
|
||||
|
||||
#ifndef BLENDER_CHANGES
|
||||
r = ((glAttachShader = (PFNGLATTACHSHADERPROC)glewGetProcAddress((const GLubyte*)"glAttachShader")) == NULL) || r;
|
||||
r = ((glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC)glewGetProcAddress((const GLubyte*)"glBindAttribLocation")) == NULL) || r;
|
||||
r = ((glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)glewGetProcAddress((const GLubyte*)"glBlendEquationSeparate")) == NULL) || r;
|
||||
@@ -1929,6 +1930,7 @@ static GLboolean _glewInit_GL_VERSION_2_0 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||
r = ((glVertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC)glewGetProcAddress((const GLubyte*)"glVertexAttrib4uiv")) == NULL) || r;
|
||||
r = ((glVertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC)glewGetProcAddress((const GLubyte*)"glVertexAttrib4usv")) == NULL) || r;
|
||||
r = ((glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)glewGetProcAddress((const GLubyte*)"glVertexAttribPointer")) == NULL) || r;
|
||||
#endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@
|
||||
#ifndef MEM_MALLOCN_H
|
||||
#define MEM_MALLOCN_H
|
||||
|
||||
/* Needed for FILE* */
|
||||
#include "stdio.h"
|
||||
#include "stdio.h" /* needed for FILE* */
|
||||
#include "BLO_sys_types.h" /* needed for uintptr_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -123,6 +123,12 @@ extern "C" {
|
||||
/** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */
|
||||
void MEM_set_memory_debug(void);
|
||||
|
||||
/* Memory usage stats
|
||||
* - MEM_get_memory_in_use is all memory
|
||||
* - MEM_get_mapped_memory_in_use is a subset of all memory */
|
||||
uintptr_t MEM_get_memory_in_use(void);
|
||||
uintptr_t MEM_get_mapped_memory_in_use(void);
|
||||
int MEM_get_memory_blocks_in_use(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLO_sys_types.h" // needed for intptr_t
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* Data definition */
|
||||
/* --------------------------------------------------------------------- */
|
||||
@@ -113,8 +111,8 @@ static const char *check_memlist(MemHead *memh);
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
|
||||
volatile int totblock= 0;
|
||||
volatile uintptr_t mem_in_use= 0, mmap_in_use= 0;
|
||||
static volatile int totblock= 0;
|
||||
static volatile uintptr_t mem_in_use= 0, mmap_in_use= 0;
|
||||
|
||||
static volatile struct localListBase _membase;
|
||||
static volatile struct localListBase *membase = &_membase;
|
||||
@@ -698,4 +696,19 @@ static const char *check_memlist(MemHead *memh)
|
||||
return(name);
|
||||
}
|
||||
|
||||
uintptr_t MEM_get_memory_in_use(void)
|
||||
{
|
||||
return mem_in_use;
|
||||
}
|
||||
|
||||
uintptr_t MEM_get_mapped_memory_in_use(void)
|
||||
{
|
||||
return mmap_in_use;
|
||||
}
|
||||
|
||||
int MEM_get_memory_blocks_in_use(void)
|
||||
{
|
||||
return totblock;
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#define __MEM_Allocator_h_included__ 1
|
||||
|
||||
#include "guardedalloc/MEM_guardedalloc.h"
|
||||
#include "guardedalloc/BLO_sys_types.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER < 1300 // 1200 == VC++ 6.0 according to boost
|
||||
|
||||
@@ -61,11 +61,8 @@ class MEM_CacheLimiter;
|
||||
|
||||
#ifndef __MEM_cache_limiter_c_api_h_included__
|
||||
extern "C" {
|
||||
extern void MEM_CacheLimiter_set_maximum(int m);
|
||||
extern int MEM_CacheLimiter_get_maximum();
|
||||
// this is rather _ugly_!
|
||||
extern int mem_in_use;
|
||||
extern int mmap_in_use;
|
||||
extern void MEM_CacheLimiter_set_maximum(intptr_t m);
|
||||
extern intptr_t MEM_CacheLimiter_get_maximum();
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -141,7 +138,10 @@ public:
|
||||
delete handle;
|
||||
}
|
||||
void enforce_limits() {
|
||||
int max = MEM_CacheLimiter_get_maximum();
|
||||
intptr_t max = MEM_CacheLimiter_get_maximum();
|
||||
intptr_t mem_in_use= MEM_get_memory_in_use();
|
||||
intptr_t mmap_in_use= MEM_get_mapped_memory_in_use();
|
||||
|
||||
if (max == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,18 +27,18 @@
|
||||
#include "MEM_CacheLimiter.h"
|
||||
#include "MEM_CacheLimiterC-Api.h"
|
||||
|
||||
static int & get_max()
|
||||
static intptr_t & get_max()
|
||||
{
|
||||
static int m = 32*1024*1024;
|
||||
static intptr_t m = 32*1024*1024;
|
||||
return m;
|
||||
}
|
||||
|
||||
void MEM_CacheLimiter_set_maximum(int m)
|
||||
void MEM_CacheLimiter_set_maximum(intptr_t m)
|
||||
{
|
||||
get_max() = m;
|
||||
}
|
||||
|
||||
int MEM_CacheLimiter_get_maximum()
|
||||
intptr_t MEM_CacheLimiter_get_maximum()
|
||||
{
|
||||
return get_max();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,19 @@ public:
|
||||
m_buckets[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GEN_Map(const GEN_Map& map)
|
||||
{
|
||||
m_num_buckets = map.m_num_buckets;
|
||||
m_buckets = new Entry *[m_num_buckets];
|
||||
|
||||
for (int i = 0; i < m_num_buckets; ++i) {
|
||||
m_buckets[i] = 0;
|
||||
|
||||
for(Entry *entry = map.m_buckets[i]; entry; entry=entry->m_next)
|
||||
insert(entry->m_key, entry->m_value);
|
||||
}
|
||||
}
|
||||
|
||||
int size() {
|
||||
int count=0;
|
||||
|
||||
@@ -212,6 +212,7 @@ public:
|
||||
MT_Matrix4x4 transposed() const;
|
||||
void transpose();
|
||||
|
||||
MT_Matrix4x4 inverse() const;
|
||||
void invert();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -52,14 +52,14 @@ GEN_INLINE void MT_Matrix4x4::invert() {
|
||||
}
|
||||
}
|
||||
|
||||
/* We do things slightly different here, because the invert() modifies
|
||||
* the buffer itself. This makes it impossible to make this op right
|
||||
* away. Like other, still missing facilities, I will repair this
|
||||
* later. */
|
||||
/* GEN_INLINE T_Matrix4x4 MT_Matrix4x4::inverse() const */
|
||||
/* { */
|
||||
/* } */
|
||||
GEN_INLINE MT_Matrix4x4 MT_Matrix4x4::inverse() const
|
||||
{
|
||||
MT_Matrix4x4 invmat = *this;
|
||||
|
||||
invmat.invert();
|
||||
|
||||
return invmat;
|
||||
}
|
||||
|
||||
GEN_INLINE MT_Matrix4x4& MT_Matrix4x4::operator*=(const MT_Matrix4x4& m)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,8 @@ output = Blender.Text.New(output_filename)
|
||||
|
||||
output.write(header + "\n\n")
|
||||
|
||||
output.write("%s\n\n" % Blender.Get('buildinfo'))
|
||||
|
||||
output.write("Platform: %s\n========\n\n" % sys.platform)
|
||||
|
||||
output.write("Python:\n======\n\n")
|
||||
|
||||
@@ -104,6 +104,8 @@ COMLIB += $(NAN_OPENNL)/lib/$(DEBUG_DIR)libopennl.a
|
||||
COMLIB += $(NAN_SUPERLU)/lib/$(DEBUG_DIR)libsuperlu.a
|
||||
COMLIB += $(OCGDIR)/blender/avi/$(DEBUG_DIR)libavi.a
|
||||
COMLIB += $(NAN_JPEG)/lib/libjpeg.a
|
||||
COMLIB += $(OCGDIR)/blender/gpu/$(DEBUG_DIR)libgpu.a
|
||||
COMLIB += $(NAN_GLEW)/lib/libglew.a
|
||||
|
||||
ifneq ($(NAN_NO_KETSJI),true)
|
||||
COMLIB += $(OCGDIR)/gameengine/bloutines/$(DEBUG_DIR)libbloutines.a
|
||||
@@ -157,7 +159,6 @@ COMLIB += $(NAN_BMFONT)/lib/$(DEBUG_DIR)libbmfont.a
|
||||
COMLIB += $(NAN_PNG)/lib/libpng.a
|
||||
COMLIB += $(OCGDIR)/blender/yafray/$(DEBUG_DIR)libyafrayexport.a
|
||||
COMLIB += $(OCGDIR)/blender/blenlib/$(DEBUG_DIR)libblenlib.a
|
||||
COMLIB += $(NAN_GLEW)/lib/libglew.a
|
||||
|
||||
ifeq ($(WITH_QUICKTIME), true)
|
||||
COMLIB += $(OCGDIR)/blender/blenderqt/$(DEBUG_DIR)libblenderqt.a
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
SUBDIRS(avi nodes blenkernel blenlib blenloader blenpluginapi imbuf imbuf/intern/cineon makesdna python radiosity readblenfile render src yafray)
|
||||
SUBDIRS(avi nodes blenkernel blenlib blenloader blenpluginapi imbuf imbuf/intern/cineon gpu makesdna python radiosity readblenfile render src yafray)
|
||||
|
||||
IF(WITH_INTERNATIONAL)
|
||||
SUBDIRS(ftfont)
|
||||
|
||||
@@ -33,7 +33,7 @@ include nan_definitions.mk
|
||||
DIRS = blenloader readblenfile
|
||||
DIRS += avi imbuf render radiosity blenlib blenkernel blenpluginapi
|
||||
DIRS += makesdna src yafray
|
||||
DIRS += python nodes
|
||||
DIRS += python nodes gpu
|
||||
|
||||
ifeq ($(WITH_FREETYPE2), true)
|
||||
DIRS += ftfont
|
||||
|
||||
@@ -7,6 +7,7 @@ SConscript(['avi/SConscript',
|
||||
'blenlib/SConscript',
|
||||
'blenloader/SConscript',
|
||||
'blenpluginapi/SConscript',
|
||||
'gpu/SConscript',
|
||||
'imbuf/SConscript',
|
||||
'imbuf/intern/cineon/SConscript',
|
||||
'makesdna/SConscript',
|
||||
|
||||
@@ -55,6 +55,7 @@ struct EditMesh;
|
||||
struct ModifierData;
|
||||
struct MCol;
|
||||
struct ColorBand;
|
||||
struct GPUVertexAttribs;
|
||||
|
||||
/* number of sub-elements each mesh element has (for interpolation) */
|
||||
#define SUB_ELEMS_VERT 0
|
||||
@@ -198,7 +199,8 @@ struct DerivedMesh {
|
||||
*
|
||||
* Also called for *final* editmode DerivedMeshes
|
||||
*/
|
||||
void (*drawFacesSolid)(DerivedMesh *dm, int (*setMaterial)(int));
|
||||
void (*drawFacesSolid)(DerivedMesh *dm,
|
||||
int (*setMaterial)(int, void *attribs));
|
||||
|
||||
/* Draw all faces
|
||||
* o If useTwoSided, draw front and back using col arrays
|
||||
@@ -215,6 +217,13 @@ struct DerivedMesh {
|
||||
int (*setDrawOptions)(struct MTFace *tface,
|
||||
struct MCol *mcol, int matnr));
|
||||
|
||||
/* Draw all faces with GLSL materials
|
||||
* o setMaterial is called for every different material nr
|
||||
* o Only if setMaterial returns true
|
||||
*/
|
||||
void (*drawFacesGLSL)(DerivedMesh *dm,
|
||||
int (*setMaterial)(int, void *attribs));
|
||||
|
||||
/* Draw mapped faces (no color, or texture)
|
||||
* o Only if !setDrawOptions or
|
||||
* setDrawOptions(userData, mapped-face-index, drawSmooth_r)
|
||||
@@ -241,6 +250,15 @@ struct DerivedMesh {
|
||||
int index),
|
||||
void *userData);
|
||||
|
||||
/* Draw mapped faces with GLSL materials
|
||||
* o setMaterial is called for every different material nr
|
||||
* o setDrawOptions is called for every face
|
||||
* o Only if setMaterial and setDrawOptions return true
|
||||
*/
|
||||
void (*drawMappedFacesGLSL)(DerivedMesh *dm,
|
||||
int (*setMaterial)(int, void *attribs),
|
||||
int (*setDrawOptions)(void *userData, int index), void *userData);
|
||||
|
||||
/* Draw mapped edges as lines
|
||||
* o Only if !setDrawOptions or setDrawOptions(userData, mapped-edge)
|
||||
* returns true
|
||||
@@ -437,6 +455,35 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb);
|
||||
/* determines required DerivedMesh data according to view and edit modes */
|
||||
CustomDataMask get_viewedit_datamask();
|
||||
|
||||
/* convert layers requested by a GLSL material to actually available layers in
|
||||
* the DerivedMesh, with both a pointer for arrays and an offset for editmesh */
|
||||
typedef struct DMVertexAttribs {
|
||||
struct {
|
||||
struct MTFace *array;
|
||||
int emOffset, glIndex;
|
||||
} tface[MAX_MTFACE];
|
||||
|
||||
struct {
|
||||
struct MCol *array;
|
||||
int emOffset, glIndex;
|
||||
} mcol[MAX_MCOL];
|
||||
|
||||
struct {
|
||||
float (*array)[3];
|
||||
int emOffset, glIndex;
|
||||
} tang;
|
||||
|
||||
struct {
|
||||
float (*array)[3];
|
||||
int emOffset, glIndex;
|
||||
} orco;
|
||||
|
||||
int tottface, totmcol, tottang, totorco;
|
||||
} DMVertexAttribs;
|
||||
|
||||
void DM_vertex_attributes_from_gpu(DerivedMesh *dm,
|
||||
struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
|
||||
|
||||
void DM_add_tangent_layer(DerivedMesh *dm);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -115,10 +115,6 @@ void free_editArmature(void);
|
||||
void docenter_new(void);
|
||||
int saveover(char *str);
|
||||
|
||||
/* image.c */
|
||||
#include "DNA_image_types.h"
|
||||
void free_realtime_image(Image *ima); // has to become a callback, opengl stuff
|
||||
|
||||
/* ipo.c */
|
||||
void copy_view3d_lock(short val); // was a hack, to make scene layer ipo's possible
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ void curvemapping_do_ibuf(struct CurveMapping *cumap, struct ImBuf *ibuf);
|
||||
void curvemapping_premultiply(struct CurveMapping *cumap, int restore);
|
||||
int curvemapping_RGBA_does_something(struct CurveMapping *cumap);
|
||||
void curvemapping_initialize(struct CurveMapping *cumap);
|
||||
void curvemapping_table_RGBA(struct CurveMapping *cumap, float **array, int *size);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -218,8 +218,15 @@ typedef struct Global {
|
||||
#define G_FILE_NO_UI (1 << 10)
|
||||
#define G_FILE_GAME_TO_IPO (1 << 11)
|
||||
#define G_FILE_GAME_MAT (1 << 12)
|
||||
#define G_FILE_DIAPLAY_LISTS (1 << 13)
|
||||
#define G_FILE_DISPLAY_LISTS (1 << 13)
|
||||
#define G_FILE_SHOW_PHYSICS (1 << 14)
|
||||
#define G_FILE_GAME_MAT_GLSL (1 << 15)
|
||||
#define G_FILE_GLSL_NO_LIGHTS (1 << 16)
|
||||
#define G_FILE_GLSL_NO_SHADERS (1 << 17)
|
||||
#define G_FILE_GLSL_NO_SHADOWS (1 << 18)
|
||||
#define G_FILE_GLSL_NO_RAMPS (1 << 19)
|
||||
#define G_FILE_GLSL_NO_NODES (1 << 20)
|
||||
#define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21)
|
||||
|
||||
/* G.windowstate */
|
||||
#define G_WINDOWSTATE_USERDEF 0
|
||||
|
||||
@@ -68,7 +68,6 @@ void mball_to_mesh(struct ListBase *lb, struct Mesh *me);
|
||||
void nurbs_to_mesh(struct Object *ob);
|
||||
void free_dverts(struct MDeformVert *dvert, int totvert);
|
||||
void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */
|
||||
int update_realtime_texture(struct MTFace *tface, double time);
|
||||
void mesh_delete_material_index(struct Mesh *me, int index);
|
||||
void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth);
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ struct rctf;
|
||||
struct ListBase;
|
||||
struct RenderData;
|
||||
struct Scene;
|
||||
struct GPUMaterial;
|
||||
struct GPUNode;
|
||||
struct GPUNodeStack;
|
||||
|
||||
#define SOCK_IN 1
|
||||
#define SOCK_OUT 2
|
||||
@@ -91,6 +94,9 @@ typedef struct bNodeType {
|
||||
void *pynode; /* holds pointer to python script */
|
||||
void *pydict; /* holds pointer to python script dictionary (scope)*/
|
||||
|
||||
/* gpu */
|
||||
int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
|
||||
|
||||
} bNodeType;
|
||||
|
||||
/* node->exec, now in use for composites (#define for break is same as ready yes) */
|
||||
@@ -252,6 +258,8 @@ void nodeShaderSynchronizeID(struct bNode *node, int copyto);
|
||||
extern void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *);
|
||||
void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *));
|
||||
|
||||
void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
|
||||
|
||||
|
||||
/* ************** COMPOSITE NODES *************** */
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ void free_plugin_tex(struct PluginTex *pit);
|
||||
void init_colorband(struct ColorBand *coba, int rangetype);
|
||||
struct ColorBand *add_colorband(int rangetype);
|
||||
int do_colorband(struct ColorBand *coba, float in, float out[4]);
|
||||
void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size);
|
||||
|
||||
void default_tex(struct Tex *tex);
|
||||
struct Tex *add_texture(char *name);
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
#define ELEM7(a, b, c, d, e, f, g, h) ( ELEM3(a, b, c, d) || ELEM4(a, e, f, g, h) )
|
||||
#define ELEM8(a, b, c, d, e, f, g, h, i) ( ELEM4(a, b, c, d, e) || ELEM4(a, f, g, h, i) )
|
||||
#define ELEM9(a, b, c, d, e, f, g, h, i, j) ( ELEM4(a, b, c, d, e) || ELEM5(a, f, g, h, i, j) )
|
||||
#define ELEM10(a, b, c, d, e, f, g, h, i, j, k) ( ELEM4(a, b, c, d, e) || ELEM6(a, f, g, h, i, j, k) )
|
||||
#define ELEM11(a, b, c, d, e, f, g, h, i, j, k, l) ( ELEM4(a, b, c, d, e) || ELEM7(a, f, g, h, i, j, k, l) )
|
||||
|
||||
/* shift around elements */
|
||||
#define SHIFT3(type, a, b, c) { type tmp; tmp = a; a = c; c = b; b = tmp; }
|
||||
|
||||
@@ -32,7 +32,7 @@ SET(INC
|
||||
../imbuf ../avi ../../../intern/elbeem/extern ../../../intern/opennl/extern
|
||||
../../../intern/iksolver/extern ../blenloader ../quicktime
|
||||
../../../intern/bmfont ../../../extern/bullet2/src
|
||||
../nodes
|
||||
../nodes ../../../extern/glew/include ../gpu
|
||||
${SDL_INC}
|
||||
${ZLIB_INC}
|
||||
${PYTHON_INC}
|
||||
|
||||
@@ -10,6 +10,7 @@ incs += ' #/intern/iksolver/extern ../blenloader ../quicktime'
|
||||
incs += ' #/extern/bullet2/src'
|
||||
incs += ' #/intern/bmfont'
|
||||
incs += ' #/intern/opennl/extern'
|
||||
incs += ' ../gpu #/extern/glew/include'
|
||||
|
||||
incs += ' ' + env['BF_PYTHON_INC']
|
||||
incs += ' ' + env['BF_OPENGL_INC']
|
||||
|
||||
@@ -176,10 +176,6 @@ void free_editMesh(struct EditMesh *em){}
|
||||
void docenter_new(void){}
|
||||
int saveover(char *str){ return 0;}
|
||||
|
||||
/* image.c */
|
||||
#include "DNA_image_types.h"
|
||||
void free_realtime_image(Image *ima){} // has to become a callback, opengl stuff
|
||||
|
||||
/* ipo.c */
|
||||
void copy_view3d_lock(short val){} // was a hack, to make scene layer ipo's possible
|
||||
|
||||
|
||||
@@ -88,6 +88,10 @@
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "GPU_draw.h"
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_material.h"
|
||||
|
||||
// headers for fluidsim bobj meshes
|
||||
#include <stdlib.h>
|
||||
#include "LBM_fluidsim.h"
|
||||
@@ -411,6 +415,8 @@ void DM_swap_face_data(DerivedMesh *dm, int index, int *corner_indices)
|
||||
CustomData_swap(&dm->faceData, index, corner_indices);
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
static DerivedMesh *getMeshDerivedMesh(Mesh *me, Object *ob, float (*vertCos)[3])
|
||||
{
|
||||
DerivedMesh *dm = CDDM_from_mesh(me, ob);
|
||||
@@ -894,6 +900,162 @@ static void emDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void
|
||||
emDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData);
|
||||
}
|
||||
|
||||
static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
|
||||
int (*setMaterial)(int, void *attribs),
|
||||
int (*setDrawOptions)(void *userData, int index), void *userData)
|
||||
{
|
||||
EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
|
||||
EditMesh *em= emdm->em;
|
||||
float (*vertexCos)[3]= emdm->vertexCos;
|
||||
float (*vertexNos)[3]= emdm->vertexNos;
|
||||
EditVert *eve;
|
||||
EditFace *efa;
|
||||
DMVertexAttribs attribs;
|
||||
GPUVertexAttribs gattribs;
|
||||
MTFace *tf;
|
||||
int transp, new_transp, orig_transp, tfoffset;
|
||||
int i, b, matnr, new_matnr, dodraw, layer;
|
||||
|
||||
dodraw = 0;
|
||||
matnr = -1;
|
||||
|
||||
transp = GPU_get_material_blend_mode();
|
||||
orig_transp = transp;
|
||||
layer = CustomData_get_layer_index(&em->fdata, CD_MTFACE);
|
||||
tfoffset = (layer == -1)? -1: em->fdata.layers[layer].offset;
|
||||
|
||||
memset(&attribs, 0, sizeof(attribs));
|
||||
|
||||
/* always use smooth shading even for flat faces, else vertex colors wont interpolate */
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
for (i=0,eve=em->verts.first; eve; eve= eve->next)
|
||||
eve->tmp.l = (long) i++;
|
||||
|
||||
#define PASSATTRIB(efa, eve, vert) { \
|
||||
if(attribs.totorco) { \
|
||||
float *orco = attribs.orco.array[eve->tmp.l]; \
|
||||
glVertexAttrib3fvARB(attribs.orco.glIndex, orco); \
|
||||
} \
|
||||
for(b = 0; b < attribs.tottface; b++) { \
|
||||
MTFace *tf = (MTFace*)((char*)efa->data + attribs.tface[b].emOffset); \
|
||||
glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]); \
|
||||
} \
|
||||
for(b = 0; b < attribs.totmcol; b++) { \
|
||||
MCol *cp = (MCol*)((char*)efa->data + attribs.mcol[b].emOffset); \
|
||||
GLubyte col[4]; \
|
||||
col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; \
|
||||
glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col); \
|
||||
} \
|
||||
if(attribs.tottang) { \
|
||||
float *tang = attribs.tang.array[i*4 + vert]; \
|
||||
glVertexAttrib3fvARB(attribs.tang.glIndex, tang); \
|
||||
} \
|
||||
}
|
||||
|
||||
for (i=0,efa= em->faces.first; efa; i++,efa= efa->next) {
|
||||
int drawSmooth= (efa->flag & ME_SMOOTH);
|
||||
|
||||
if(setDrawOptions && !setDrawOptions(userData, i))
|
||||
continue;
|
||||
|
||||
new_matnr = efa->mat_nr + 1;
|
||||
if(new_matnr != matnr) {
|
||||
dodraw = setMaterial(matnr = new_matnr, &gattribs);
|
||||
if(dodraw)
|
||||
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
|
||||
}
|
||||
|
||||
if(tfoffset != -1) {
|
||||
tf = (MTFace*)((char*)efa->data)+tfoffset;
|
||||
new_transp = tf->transp;
|
||||
|
||||
if(new_transp != transp) {
|
||||
if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
|
||||
GPU_set_material_blend_mode(orig_transp);
|
||||
else
|
||||
GPU_set_material_blend_mode(new_transp);
|
||||
transp = new_transp;
|
||||
}
|
||||
}
|
||||
|
||||
if(dodraw) {
|
||||
glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
|
||||
if (!drawSmooth) {
|
||||
if(vertexCos) glNormal3fv(emdm->faceNos[i]);
|
||||
else glNormal3fv(efa->n);
|
||||
|
||||
PASSATTRIB(efa, efa->v1, 0);
|
||||
if(vertexCos) glVertex3fv(vertexCos[(int) efa->v1->tmp.l]);
|
||||
else glVertex3fv(efa->v1->co);
|
||||
|
||||
PASSATTRIB(efa, efa->v2, 1);
|
||||
if(vertexCos) glVertex3fv(vertexCos[(int) efa->v2->tmp.l]);
|
||||
else glVertex3fv(efa->v2->co);
|
||||
|
||||
PASSATTRIB(efa, efa->v3, 2);
|
||||
if(vertexCos) glVertex3fv(vertexCos[(int) efa->v3->tmp.l]);
|
||||
else glVertex3fv(efa->v3->co);
|
||||
|
||||
if(efa->v4) {
|
||||
PASSATTRIB(efa, efa->v4, 3);
|
||||
if(vertexCos) glVertex3fv(vertexCos[(int) efa->v4->tmp.l]);
|
||||
else glVertex3fv(efa->v4->co);
|
||||
}
|
||||
} else {
|
||||
PASSATTRIB(efa, efa->v1, 0);
|
||||
if(vertexCos) {
|
||||
glNormal3fv(vertexNos[(int) efa->v1->tmp.l]);
|
||||
glVertex3fv(vertexCos[(int) efa->v1->tmp.l]);
|
||||
}
|
||||
else {
|
||||
glNormal3fv(efa->v1->no);
|
||||
glVertex3fv(efa->v1->co);
|
||||
}
|
||||
|
||||
PASSATTRIB(efa, efa->v2, 1);
|
||||
if(vertexCos) {
|
||||
glNormal3fv(vertexNos[(int) efa->v2->tmp.l]);
|
||||
glVertex3fv(vertexCos[(int) efa->v2->tmp.l]);
|
||||
}
|
||||
else {
|
||||
glNormal3fv(efa->v2->no);
|
||||
glVertex3fv(efa->v2->co);
|
||||
}
|
||||
|
||||
PASSATTRIB(efa, efa->v3, 2);
|
||||
if(vertexCos) {
|
||||
glNormal3fv(vertexNos[(int) efa->v3->tmp.l]);
|
||||
glVertex3fv(vertexCos[(int) efa->v3->tmp.l]);
|
||||
}
|
||||
else {
|
||||
glNormal3fv(efa->v3->no);
|
||||
glVertex3fv(efa->v3->co);
|
||||
}
|
||||
|
||||
if(efa->v4) {
|
||||
PASSATTRIB(efa, efa->v4, 3);
|
||||
if(vertexCos) {
|
||||
glNormal3fv(vertexNos[(int) efa->v4->tmp.l]);
|
||||
glVertex3fv(vertexCos[(int) efa->v4->tmp.l]);
|
||||
}
|
||||
else {
|
||||
glNormal3fv(efa->v4->no);
|
||||
glVertex3fv(efa->v4->co);
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void emDM_drawFacesGLSL(DerivedMesh *dm,
|
||||
int (*setMaterial)(int, void *attribs))
|
||||
{
|
||||
dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
|
||||
}
|
||||
|
||||
static void emDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
|
||||
{
|
||||
EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
|
||||
@@ -1099,6 +1261,43 @@ void emDM_copyFaceArray(DerivedMesh *dm, MFace *face_r)
|
||||
}
|
||||
}
|
||||
|
||||
static void *emDM_getFaceDataArray(DerivedMesh *dm, int type)
|
||||
{
|
||||
EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
|
||||
EditMesh *em= emdm->em;
|
||||
EditFace *efa;
|
||||
char *data, *emdata;
|
||||
void *datalayer;
|
||||
int index, offset, size;
|
||||
|
||||
datalayer = DM_get_face_data_layer(dm, type);
|
||||
if(datalayer)
|
||||
return datalayer;
|
||||
|
||||
/* layers are store per face for editmesh, we convert to a temporary
|
||||
* data layer array in the derivedmesh when these are requested */
|
||||
if(type == CD_MTFACE || type == CD_MCOL) {
|
||||
index = CustomData_get_layer_index(&em->fdata, type);
|
||||
|
||||
if(index != -1) {
|
||||
offset = em->fdata.layers[index].offset;
|
||||
size = CustomData_sizeof(type);
|
||||
|
||||
DM_add_face_layer(dm, type, CD_CALLOC, NULL);
|
||||
index = CustomData_get_layer_index(&dm->faceData, type);
|
||||
dm->faceData.layers[index].flag |= CD_FLAG_TEMPORARY;
|
||||
|
||||
data = datalayer = DM_get_face_data_layer(dm, type);
|
||||
for(efa=em->faces.first; efa; efa=efa->next, data+=size) {
|
||||
emdata = CustomData_em_get(&em->fdata, efa->data, type);
|
||||
memcpy(data, emdata, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return datalayer;
|
||||
}
|
||||
|
||||
static void emDM_release(DerivedMesh *dm)
|
||||
{
|
||||
EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
|
||||
@@ -1134,6 +1333,7 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob,
|
||||
emdm->dm.copyVertArray = emDM_copyVertArray;
|
||||
emdm->dm.copyEdgeArray = emDM_copyEdgeArray;
|
||||
emdm->dm.copyFaceArray = emDM_copyFaceArray;
|
||||
emdm->dm.getFaceDataArray = emDM_getFaceDataArray;
|
||||
|
||||
emdm->dm.foreachMappedVert = emDM_foreachMappedVert;
|
||||
emdm->dm.foreachMappedEdge = emDM_foreachMappedEdge;
|
||||
@@ -1144,7 +1344,9 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob,
|
||||
emdm->dm.drawMappedEdgesInterp = emDM_drawMappedEdgesInterp;
|
||||
emdm->dm.drawMappedFaces = emDM_drawMappedFaces;
|
||||
emdm->dm.drawMappedFacesTex = emDM_drawMappedFacesTex;
|
||||
emdm->dm.drawMappedFacesGLSL = emDM_drawMappedFacesGLSL;
|
||||
emdm->dm.drawFacesTex = emDM_drawFacesTex;
|
||||
emdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
|
||||
emdm->dm.drawUVEdges = emDM_drawUVEdges;
|
||||
|
||||
emdm->dm.release = emDM_release;
|
||||
@@ -1574,7 +1776,7 @@ static void vDM_drawUVEdges(DerivedMesh *dm)
|
||||
}
|
||||
|
||||
/* draw all VerseFaces */
|
||||
static void vDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int))
|
||||
static void vDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *attribs))
|
||||
{
|
||||
VDerivedMesh *vdm = (VDerivedMesh*)dm;
|
||||
struct VerseFace *vface;
|
||||
@@ -1674,6 +1876,8 @@ static void vDM_drawMappedFacesTex(
|
||||
int (*setDrawParams)(void *userData, int index),
|
||||
void *userData)
|
||||
{
|
||||
/* not supported yet */
|
||||
vDM_drawFacesTex(dm, NULL);
|
||||
}
|
||||
|
||||
/**/
|
||||
@@ -1815,19 +2019,23 @@ CustomDataMask get_viewedit_datamask()
|
||||
ScrArea *sa;
|
||||
|
||||
/* check if we need tfaces & mcols due to face select or texture paint */
|
||||
if(FACESEL_PAINT_TEST || G.f & G_TEXTUREPAINT) {
|
||||
if(FACESEL_PAINT_TEST || G.f & G_TEXTUREPAINT)
|
||||
mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
|
||||
} else {
|
||||
/* check if we need tfaces & mcols due to view mode */
|
||||
for(sa = G.curscreen->areabase.first; sa; sa = sa->next) {
|
||||
if(sa->spacetype == SPACE_VIEW3D) {
|
||||
View3D *view = sa->spacedata.first;
|
||||
if(view->drawtype == OB_SHADED) {
|
||||
/* this includes normals for mesh_create_shadedColors */
|
||||
mask |= CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_NORMAL | CD_MASK_ORCO;
|
||||
}
|
||||
if((view->drawtype == OB_TEXTURE) || ((view->drawtype == OB_SOLID) && (view->flag2 & V3D_SOLID_TEX))) {
|
||||
mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
|
||||
|
||||
/* check if we need tfaces & mcols due to view mode */
|
||||
for(sa = G.curscreen->areabase.first; sa; sa = sa->next) {
|
||||
if(sa->spacetype == SPACE_VIEW3D) {
|
||||
View3D *view = sa->spacedata.first;
|
||||
if(view->drawtype == OB_SHADED) {
|
||||
/* this includes normals for mesh_create_shadedColors */
|
||||
mask |= CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_NORMAL | CD_MASK_ORCO;
|
||||
}
|
||||
if((view->drawtype == OB_TEXTURE) || ((view->drawtype == OB_SOLID) && (view->flag2 & V3D_SOLID_TEX))) {
|
||||
mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
|
||||
|
||||
if((G.fileflags & G_FILE_GAME_MAT) &&
|
||||
(G.fileflags & G_FILE_GAME_MAT_GLSL)) {
|
||||
mask |= CD_MASK_ORCO;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1840,13 +2048,41 @@ CustomDataMask get_viewedit_datamask()
|
||||
return mask;
|
||||
}
|
||||
|
||||
static DerivedMesh *create_orco_dm(Object *ob, Mesh *me)
|
||||
static float *get_editmesh_orco_verts(EditMesh *em)
|
||||
{
|
||||
EditVert *eve;
|
||||
float *orco;
|
||||
int a, totvert;
|
||||
|
||||
/* these may not really be the orco's, but it's only for preview.
|
||||
* could be solver better once, but isn't simple */
|
||||
|
||||
totvert= 0;
|
||||
for(eve=em->verts.first; eve; eve=eve->next)
|
||||
totvert++;
|
||||
|
||||
orco = MEM_mallocN(sizeof(float)*3*totvert, "EditMesh Orco");
|
||||
|
||||
for(a=0, eve=em->verts.first; eve; eve=eve->next, a+=3)
|
||||
VECCOPY(orco+a, eve->co);
|
||||
|
||||
return orco;
|
||||
}
|
||||
|
||||
static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, EditMesh *em)
|
||||
{
|
||||
DerivedMesh *dm;
|
||||
float (*orco)[3];
|
||||
|
||||
dm= CDDM_from_mesh(me, ob);
|
||||
orco= (float(*)[3])get_mesh_orco_verts(ob);
|
||||
if(em) {
|
||||
dm= CDDM_from_editmesh(em, me);
|
||||
orco= (float(*)[3])get_editmesh_orco_verts(em);
|
||||
}
|
||||
else {
|
||||
dm= CDDM_from_mesh(me, ob);
|
||||
orco= (float(*)[3])get_mesh_orco_verts(ob);
|
||||
}
|
||||
|
||||
CDDM_apply_vert_coords(dm, orco);
|
||||
CDDM_calc_normals(dm);
|
||||
MEM_freeN(orco);
|
||||
@@ -1854,7 +2090,7 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me)
|
||||
return dm;
|
||||
}
|
||||
|
||||
static void add_orco_dm(Object *ob, DerivedMesh *dm, DerivedMesh *orcodm)
|
||||
static void add_orco_dm(Object *ob, EditMesh *em, DerivedMesh *dm, DerivedMesh *orcodm)
|
||||
{
|
||||
float (*orco)[3], (*layerorco)[3];
|
||||
int totvert;
|
||||
@@ -1869,8 +2105,10 @@ static void add_orco_dm(Object *ob, DerivedMesh *dm, DerivedMesh *orcodm)
|
||||
else
|
||||
dm->getVertCos(dm, orco);
|
||||
}
|
||||
else
|
||||
orco= (float(*)[3])get_mesh_orco_verts(ob);
|
||||
else {
|
||||
if(em) orco= (float(*)[3])get_editmesh_orco_verts(em);
|
||||
else orco= (float(*)[3])get_mesh_orco_verts(ob);
|
||||
}
|
||||
|
||||
transform_mesh_orco_verts(ob->data, orco, totvert, 0);
|
||||
|
||||
@@ -2016,7 +2254,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3],
|
||||
if(dm && mti->requiredDataMask) {
|
||||
mask = mti->requiredDataMask(md);
|
||||
if(mask & CD_MASK_ORCO)
|
||||
add_orco_dm(ob, dm, orcodm);
|
||||
add_orco_dm(ob, NULL, dm, orcodm);
|
||||
}
|
||||
|
||||
/* How to apply modifier depends on (a) what we already have as
|
||||
@@ -2069,7 +2307,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3],
|
||||
mask= (CustomDataMask)curr->link;
|
||||
if(mask & CD_MASK_ORCO) {
|
||||
if(!orcodm)
|
||||
orcodm= create_orco_dm(ob, me);
|
||||
orcodm= create_orco_dm(ob, me, NULL);
|
||||
|
||||
mask &= ~CD_MASK_ORCO;
|
||||
DM_set_only_copy(orcodm, mask);
|
||||
@@ -2146,10 +2384,10 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3],
|
||||
|
||||
/* add an orco layer if needed */
|
||||
if(dataMask & CD_MASK_ORCO) {
|
||||
add_orco_dm(ob, finaldm, orcodm);
|
||||
add_orco_dm(ob, NULL, finaldm, orcodm);
|
||||
|
||||
if(deform_r && *deform_r)
|
||||
add_orco_dm(ob, *deform_r, NULL);
|
||||
add_orco_dm(ob, NULL, *deform_r, NULL);
|
||||
}
|
||||
|
||||
*final_r = finaldm;
|
||||
@@ -2205,7 +2443,8 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r,
|
||||
EditMesh *em = G.editMesh;
|
||||
ModifierData *md;
|
||||
float (*deformedVerts)[3] = NULL;
|
||||
DerivedMesh *dm;
|
||||
CustomDataMask mask;
|
||||
DerivedMesh *dm, *orcodm = NULL;
|
||||
int i, numVerts = 0, cageIndex = modifiers_getCageIndex(ob, NULL);
|
||||
LinkNode *datamasks, *curr;
|
||||
|
||||
@@ -2230,6 +2469,13 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r,
|
||||
if(!editmesh_modifier_is_enabled(md, dm))
|
||||
continue;
|
||||
|
||||
/* add an orco layer if needed by this modifier */
|
||||
if(dm && mti->requiredDataMask) {
|
||||
mask = mti->requiredDataMask(md);
|
||||
if(mask & CD_MASK_ORCO)
|
||||
add_orco_dm(ob, em, dm, orcodm);
|
||||
}
|
||||
|
||||
/* How to apply modifier depends on (a) what we already have as
|
||||
* a result of previous modifiers (could be a DerivedMesh or just
|
||||
* deformed vertices) and (b) what type the modifier is.
|
||||
@@ -2280,6 +2526,23 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r,
|
||||
}
|
||||
}
|
||||
|
||||
/* create an orco derivedmesh in parallel */
|
||||
mask= (CustomDataMask)curr->link;
|
||||
if(mask & CD_MASK_ORCO) {
|
||||
if(!orcodm)
|
||||
orcodm= create_orco_dm(ob, ob->data, em);
|
||||
|
||||
mask &= ~CD_MASK_ORCO;
|
||||
DM_set_only_copy(orcodm, mask);
|
||||
ndm = mti->applyModifierEM(md, ob, em, orcodm);
|
||||
|
||||
if(ndm) {
|
||||
/* if the modifier returned a new dm, release the old one */
|
||||
if(orcodm && orcodm != ndm) orcodm->release(orcodm);
|
||||
orcodm = ndm;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the DerivedMesh to only copy needed data */
|
||||
DM_set_only_copy(dm, (CustomDataMask)curr->link);
|
||||
|
||||
@@ -2338,6 +2601,13 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r,
|
||||
deformedVerts = NULL;
|
||||
}
|
||||
|
||||
/* add an orco layer if needed */
|
||||
if(dataMask & CD_MASK_ORCO)
|
||||
add_orco_dm(ob, em, *final_r, orcodm);
|
||||
|
||||
if(orcodm)
|
||||
orcodm->release(orcodm);
|
||||
|
||||
if(deformedVerts)
|
||||
MEM_freeN(deformedVerts);
|
||||
}
|
||||
@@ -2632,7 +2902,7 @@ void multires_render_final(Object *ob, Mesh *me, DerivedMesh **dm, float *vert_c
|
||||
old->release(old);
|
||||
|
||||
if(dataMask & CD_MASK_ORCO)
|
||||
add_orco_dm(ob, *dm, NULL);
|
||||
add_orco_dm(ob, NULL, *dm, NULL);
|
||||
|
||||
/* Restore the original verts */
|
||||
me->mr->newlvl= BLI_countlist(&me->mr->levels);
|
||||
@@ -2847,6 +3117,8 @@ int editmesh_get_first_deform_matrices(float (**deformmats)[3][3], float (**defo
|
||||
return numleft;
|
||||
}
|
||||
|
||||
/* ******************* GLSL ******************** */
|
||||
|
||||
void DM_add_tangent_layer(DerivedMesh *dm)
|
||||
{
|
||||
/* mesh vars */
|
||||
@@ -2967,6 +3239,91 @@ void DM_add_tangent_layer(DerivedMesh *dm)
|
||||
MEM_freeN(vtangents);
|
||||
}
|
||||
|
||||
void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, DMVertexAttribs *attribs)
|
||||
{
|
||||
CustomData *vdata, *fdata, *tfdata = NULL;
|
||||
int a, b, layer;
|
||||
|
||||
/* From the layers requested by the GLSL shader, figure out which ones are
|
||||
* actually available for this derivedmesh, and retrieve the pointers */
|
||||
|
||||
memset(attribs, 0, sizeof(DMVertexAttribs));
|
||||
|
||||
vdata = &dm->vertData;
|
||||
fdata = &dm->faceData;
|
||||
|
||||
/* ugly hack, editmesh derivedmesh doesn't copy face data, this way we
|
||||
* can use offsets instead */
|
||||
if(dm->release == emDM_release)
|
||||
tfdata = &((EditMeshDerivedMesh*)dm)->em->fdata;
|
||||
else
|
||||
tfdata = fdata;
|
||||
|
||||
/* add a tangent layer if necessary */
|
||||
for(b = 0; b < gattribs->totlayer; b++)
|
||||
if(gattribs->layer[b].type == CD_TANGENT)
|
||||
if(CustomData_get_layer_index(fdata, CD_TANGENT) == -1)
|
||||
DM_add_tangent_layer(dm);
|
||||
|
||||
for(b = 0; b < gattribs->totlayer; b++) {
|
||||
if(gattribs->layer[b].type == CD_MTFACE) {
|
||||
/* uv coordinates */
|
||||
if(gattribs->layer[b].name[0])
|
||||
layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE,
|
||||
gattribs->layer[b].name);
|
||||
else
|
||||
layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
|
||||
|
||||
if(layer != -1) {
|
||||
a = attribs->tottface++;
|
||||
|
||||
attribs->tface[a].array = tfdata->layers[layer].data;
|
||||
attribs->tface[a].emOffset = tfdata->layers[layer].offset;
|
||||
attribs->tface[a].glIndex = gattribs->layer[b].glindex;
|
||||
}
|
||||
}
|
||||
else if(gattribs->layer[b].type == CD_MCOL) {
|
||||
/* vertex colors */
|
||||
if(gattribs->layer[b].name[0])
|
||||
layer = CustomData_get_named_layer_index(tfdata, CD_MCOL,
|
||||
gattribs->layer[b].name);
|
||||
else
|
||||
layer = CustomData_get_active_layer_index(tfdata, CD_MCOL);
|
||||
|
||||
if(layer != -1) {
|
||||
a = attribs->totmcol++;
|
||||
|
||||
attribs->mcol[a].array = tfdata->layers[layer].data;
|
||||
attribs->mcol[a].emOffset = tfdata->layers[layer].offset;
|
||||
attribs->mcol[a].glIndex = gattribs->layer[b].glindex;
|
||||
}
|
||||
}
|
||||
else if(gattribs->layer[b].type == CD_TANGENT) {
|
||||
/* tangents */
|
||||
layer = CustomData_get_layer_index(fdata, CD_TANGENT);
|
||||
|
||||
if(layer != -1) {
|
||||
attribs->tottang = 1;
|
||||
|
||||
attribs->tang.array = fdata->layers[layer].data;
|
||||
attribs->tang.emOffset = fdata->layers[layer].offset;
|
||||
attribs->tang.glIndex = gattribs->layer[b].glindex;
|
||||
}
|
||||
}
|
||||
else if(gattribs->layer[b].type == CD_ORCO) {
|
||||
/* original coordinates */
|
||||
layer = CustomData_get_layer_index(vdata, CD_ORCO);
|
||||
|
||||
if(layer != -1) {
|
||||
attribs->totorco = 1;
|
||||
|
||||
attribs->orco.array = vdata->layers[layer].data;
|
||||
attribs->orco.emOffset = vdata->layers[layer].offset;
|
||||
attribs->orco.glIndex = gattribs->layer[b].glindex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************* fluidsim bobj file handling **************************** */
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ include nan_compile.mk
|
||||
CFLAGS += $(LEVEL_1_C_WARNINGS)
|
||||
|
||||
# OpenGL and Python
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += -I$(OPENGL_HEADERS)
|
||||
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
|
||||
|
||||
@@ -74,6 +75,9 @@ CPPFLAGS += -I$(NAN_ZLIB)/include
|
||||
#path to nodes
|
||||
CPPFLAGS += -I../../nodes
|
||||
|
||||
#path to gpu
|
||||
CPPFLAGS += -I../../gpu
|
||||
|
||||
# path to our own external headerfiles
|
||||
CPPFLAGS += -I..
|
||||
|
||||
|
||||
@@ -347,6 +347,8 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan
|
||||
VECCOPY(pchan->loc, chan->loc);
|
||||
VECCOPY(pchan->size, chan->size);
|
||||
QUATCOPY(pchan->quat, chan->quat);
|
||||
Mat4CpyMat4(pchan->chan_mat, (float(*)[4])chan->chan_mat);
|
||||
Mat4CpyMat4(pchan->pose_mat, (float(*)[4])chan->pose_mat);
|
||||
pchan->flag= chan->flag;
|
||||
|
||||
con= chan->constraints.first;
|
||||
|
||||
@@ -303,7 +303,7 @@ static void group_duplilist(ListBase *lb, Object *ob, int level, int animated)
|
||||
DupliObject *dob;
|
||||
Group *group;
|
||||
GroupObject *go;
|
||||
float mat[4][4];
|
||||
float mat[4][4], tmat[4][4];
|
||||
|
||||
if(ob->dup_group==NULL) return;
|
||||
group= ob->dup_group;
|
||||
@@ -320,7 +320,15 @@ static void group_duplilist(ListBase *lb, Object *ob, int level, int animated)
|
||||
/* note, if you check on layer here, render goes wrong... it still deforms verts and uses parent imat */
|
||||
if(go->ob!=ob) {
|
||||
|
||||
Mat4MulMat4(mat, go->ob->obmat, ob->obmat);
|
||||
/* Group Dupli Offset, should apply after everything else */
|
||||
if (group->dupli_ofs[0] || group->dupli_ofs[1] || group->dupli_ofs[2]) {
|
||||
Mat4CpyMat4(tmat, go->ob->obmat);
|
||||
VecSubf(tmat[3], tmat[3], group->dupli_ofs);
|
||||
Mat4MulMat4(mat, tmat, ob->obmat);
|
||||
} else {
|
||||
Mat4MulMat4(mat, go->ob->obmat, ob->obmat);
|
||||
}
|
||||
|
||||
dob= new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated);
|
||||
dob->no_draw= (dob->origlay & group->layer)==0;
|
||||
|
||||
@@ -1059,7 +1067,8 @@ static void object_duplilist_recursive(ID *id, Object *ob, ListBase *duplilist,
|
||||
}
|
||||
}
|
||||
|
||||
/* note; group dupli's already set transform matrix. see note in group_duplilist() */
|
||||
/* Returns a list of DupliObject
|
||||
* note; group dupli's already set transform matrix. see note in group_duplilist() */
|
||||
ListBase *object_duplilist(Scene *sce, Object *ob)
|
||||
{
|
||||
ListBase *duplilist= MEM_mallocN(sizeof(ListBase), "duplilist");
|
||||
|
||||
@@ -525,6 +525,7 @@ typedef struct UndoElem {
|
||||
char str[FILE_MAXDIR+FILE_MAXFILE];
|
||||
char name[MAXUNDONAME];
|
||||
MemFile memfile;
|
||||
uintptr_t undosize;
|
||||
} UndoElem;
|
||||
|
||||
static ListBase undobase={NULL, NULL};
|
||||
@@ -555,6 +556,7 @@ static int read_undosave(UndoElem *uel)
|
||||
/* name can be a dynamic string */
|
||||
void BKE_write_undo(char *name)
|
||||
{
|
||||
uintptr_t maxmem, totmem, memused;
|
||||
int nr, success;
|
||||
UndoElem *uel;
|
||||
|
||||
@@ -616,8 +618,36 @@ void BKE_write_undo(char *name)
|
||||
|
||||
if(curundo->prev) prevfile= &(curundo->prev->memfile);
|
||||
|
||||
memused= MEM_get_memory_in_use();
|
||||
success= BLO_write_file_mem(prevfile, &curundo->memfile, G.fileflags, &err);
|
||||
|
||||
curundo->undosize= MEM_get_memory_in_use() - memused;
|
||||
}
|
||||
|
||||
if(U.undomemory != 0) {
|
||||
/* limit to maximum memory (afterwards, we can't know in advance) */
|
||||
totmem= 0;
|
||||
maxmem= ((uintptr_t)U.undomemory)*1024*1024;
|
||||
|
||||
/* keep at least two (original + other) */
|
||||
uel= undobase.last;
|
||||
while(uel && uel->prev) {
|
||||
totmem+= uel->undosize;
|
||||
if(totmem>maxmem) break;
|
||||
uel= uel->prev;
|
||||
}
|
||||
|
||||
if(uel) {
|
||||
if(uel->prev && uel->prev->prev)
|
||||
uel= uel->prev;
|
||||
|
||||
while(undobase.first!=uel) {
|
||||
UndoElem *first= undobase.first;
|
||||
BLI_remlink(&undobase, first);
|
||||
/* the merge is because of compression */
|
||||
BLO_merge_memfile(&first->memfile, &first->next->memfile);
|
||||
MEM_freeN(first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,14 +713,14 @@ char *BKE_undo_menu_string(void)
|
||||
UndoElem *uel;
|
||||
DynStr *ds= BLI_dynstr_new();
|
||||
char *menu;
|
||||
|
||||
|
||||
BLI_dynstr_append(ds, "Global Undo History %t");
|
||||
|
||||
for(uel= undobase.first; uel; uel= uel->next) {
|
||||
BLI_dynstr_append(ds, "|");
|
||||
BLI_dynstr_append(ds, uel->name);
|
||||
}
|
||||
|
||||
|
||||
menu= BLI_dynstr_get_cstring(ds);
|
||||
BLI_dynstr_free(ds);
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "GPU_draw.h"
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_material.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
@@ -243,7 +247,7 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm)
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static void cdDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int))
|
||||
static void cdDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *attribs))
|
||||
{
|
||||
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
|
||||
MVert *mvert = cddm->mvert;
|
||||
@@ -271,7 +275,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int))
|
||||
|| new_shademodel != shademodel) {
|
||||
glEnd();
|
||||
|
||||
drawCurrentMat = setMaterial(matnr = new_matnr);
|
||||
drawCurrentMat = setMaterial(matnr = new_matnr, NULL);
|
||||
|
||||
glShadeModel(shademodel = new_shademodel);
|
||||
glBegin(glmode = new_glmode);
|
||||
@@ -556,6 +560,134 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void
|
||||
cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData);
|
||||
}
|
||||
|
||||
static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs), int (*setDrawOptions)(void *userData, int index), void *userData)
|
||||
{
|
||||
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
|
||||
GPUVertexAttribs gattribs;
|
||||
DMVertexAttribs attribs;
|
||||
MVert *mvert = cddm->mvert;
|
||||
MFace *mface = cddm->mface;
|
||||
MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE);
|
||||
float (*nors)[3] = dm->getFaceDataArray(dm, CD_NORMAL);
|
||||
int a, b, dodraw, smoothnormal, matnr, new_matnr;
|
||||
int transp, new_transp, orig_transp;
|
||||
int orig, *index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
|
||||
|
||||
matnr = -1;
|
||||
smoothnormal = 0;
|
||||
dodraw = 0;
|
||||
transp = GPU_get_material_blend_mode();
|
||||
orig_transp = transp;
|
||||
|
||||
memset(&attribs, 0, sizeof(attribs));
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
for(a = 0; a < dm->numFaceData; a++, mface++) {
|
||||
new_matnr = mface->mat_nr + 1;
|
||||
|
||||
if(new_matnr != matnr) {
|
||||
glEnd();
|
||||
|
||||
dodraw = setMaterial(matnr = new_matnr, &gattribs);
|
||||
if(dodraw)
|
||||
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
}
|
||||
|
||||
if(!dodraw) {
|
||||
continue;
|
||||
}
|
||||
else if(setDrawOptions) {
|
||||
orig = index[a];
|
||||
|
||||
if(orig == ORIGINDEX_NONE)
|
||||
continue;
|
||||
else if(!setDrawOptions(userData, orig))
|
||||
continue;
|
||||
}
|
||||
|
||||
if(tf) {
|
||||
new_transp = tf[a].transp;
|
||||
|
||||
if(new_transp != transp) {
|
||||
glEnd();
|
||||
|
||||
if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
|
||||
GPU_set_material_blend_mode(orig_transp);
|
||||
else
|
||||
GPU_set_material_blend_mode(new_transp);
|
||||
transp = new_transp;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
}
|
||||
}
|
||||
|
||||
smoothnormal = (mface->flag & ME_SMOOTH);
|
||||
|
||||
if(!smoothnormal) {
|
||||
if(nors) {
|
||||
glNormal3fv(nors[a]);
|
||||
}
|
||||
else {
|
||||
/* TODO ideally a normal layer should always be available */
|
||||
float nor[3];
|
||||
if(mface->v4) {
|
||||
CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co,
|
||||
mvert[mface->v3].co, mvert[mface->v4].co,
|
||||
nor);
|
||||
} else {
|
||||
CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co,
|
||||
mvert[mface->v3].co, nor);
|
||||
}
|
||||
glNormal3fv(nor);
|
||||
}
|
||||
}
|
||||
|
||||
#define PASSVERT(index, vert) { \
|
||||
if(attribs.totorco) \
|
||||
glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]); \
|
||||
for(b = 0; b < attribs.tottface; b++) { \
|
||||
MTFace *tf = &attribs.tface[b].array[a]; \
|
||||
glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]); \
|
||||
} \
|
||||
for(b = 0; b < attribs.totmcol; b++) { \
|
||||
MCol *cp = &attribs.mcol[b].array[a*4 + vert]; \
|
||||
GLubyte col[4]; \
|
||||
col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; \
|
||||
glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col); \
|
||||
} \
|
||||
if(attribs.tottang) { \
|
||||
float *tang = attribs.tang.array[a*4 + vert]; \
|
||||
glVertexAttrib3fvARB(attribs.tang.glIndex, tang); \
|
||||
} \
|
||||
if(smoothnormal) \
|
||||
glNormal3sv(mvert[index].no); \
|
||||
glVertex3fv(mvert[index].co); \
|
||||
}
|
||||
|
||||
PASSVERT(mface->v1, 0);
|
||||
PASSVERT(mface->v2, 1);
|
||||
PASSVERT(mface->v3, 2);
|
||||
if(mface->v4)
|
||||
PASSVERT(mface->v4, 3)
|
||||
else
|
||||
PASSVERT(mface->v3, 2)
|
||||
|
||||
#undef PASSVERT
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
}
|
||||
|
||||
static void cdDM_drawFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs))
|
||||
{
|
||||
dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
|
||||
}
|
||||
|
||||
static void cdDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void *userData)
|
||||
{
|
||||
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
|
||||
@@ -713,8 +845,10 @@ static CDDerivedMesh *cdDM_create(const char *desc)
|
||||
dm->drawFacesSolid = cdDM_drawFacesSolid;
|
||||
dm->drawFacesColored = cdDM_drawFacesColored;
|
||||
dm->drawFacesTex = cdDM_drawFacesTex;
|
||||
dm->drawFacesGLSL = cdDM_drawFacesGLSL;
|
||||
dm->drawMappedFaces = cdDM_drawMappedFaces;
|
||||
dm->drawMappedFacesTex = cdDM_drawMappedFacesTex;
|
||||
dm->drawMappedFacesGLSL = cdDM_drawMappedFacesGLSL;
|
||||
|
||||
dm->foreachMappedVert = cdDM_foreachMappedVert;
|
||||
dm->foreachMappedEdge = cdDM_foreachMappedEdge;
|
||||
|
||||
@@ -730,3 +730,24 @@ void curvemapping_initialize(CurveMapping *cumap)
|
||||
curvemap_make_table(cumap->cm+a, &cumap->clipr);
|
||||
}
|
||||
}
|
||||
|
||||
void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size)
|
||||
{
|
||||
int a;
|
||||
|
||||
*size = CM_TABLE+1;
|
||||
*array = MEM_callocN(sizeof(float)*(*size)*4, "CurveMapping");
|
||||
curvemapping_initialize(cumap);
|
||||
|
||||
for(a=0; a<*size; a++) {
|
||||
if(cumap->cm[0].table)
|
||||
(*array)[a*4+0]= cumap->cm[0].table[a].y;
|
||||
if(cumap->cm[1].table)
|
||||
(*array)[a*4+1]= cumap->cm[1].table[a].y;
|
||||
if(cumap->cm[2].table)
|
||||
(*array)[a*4+2]= cumap->cm[2].table[a].y;
|
||||
if(cumap->cm[3].table)
|
||||
(*array)[a*4+3]= cumap->cm[3].table[a].y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "DNA_packedFile_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_sequence_types.h"
|
||||
#include "DNA_texture_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
|
||||
@@ -77,15 +78,15 @@
|
||||
|
||||
#include "RE_pipeline.h"
|
||||
|
||||
/* bad level; call to free_realtime_image */
|
||||
#include "BKE_bad_level_calls.h"
|
||||
|
||||
/* for stamp drawing to an image */
|
||||
#include "BMF_Api.h"
|
||||
|
||||
#include "blendef.h"
|
||||
#include "BSE_time.h"
|
||||
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_draw.h"
|
||||
|
||||
#include "BLO_sys_types.h" // for intptr_t support
|
||||
|
||||
/* max int, to indicate we don't store sequences in ibuf */
|
||||
@@ -240,7 +241,7 @@ static void image_free_buffers(Image *ima)
|
||||
ima->rr= NULL;
|
||||
}
|
||||
|
||||
free_realtime_image(ima);
|
||||
GPU_free_image(ima);
|
||||
|
||||
ima->ok= IMA_OK;
|
||||
}
|
||||
@@ -620,7 +621,7 @@ void free_old_images()
|
||||
This gives textures a "second chance" to be used before dying.
|
||||
*/
|
||||
if(ima->bindcode || ima->repbind) {
|
||||
free_realtime_image(ima);
|
||||
GPU_free_image(ima);
|
||||
ima->lastused = ctime;
|
||||
}
|
||||
/* Otherwise, just kill the buffers */
|
||||
|
||||
@@ -1390,6 +1390,14 @@ void *get_ipo_poin(ID *id, IpoCurve *icu, int *type)
|
||||
else if(icu->adrcode & MA_MAP8) mtex= ma->mtex[7];
|
||||
else if(icu->adrcode & MA_MAP9) mtex= ma->mtex[8];
|
||||
else if(icu->adrcode & MA_MAP10) mtex= ma->mtex[9];
|
||||
else if(icu->adrcode & MA_MAP12) mtex= ma->mtex[11];
|
||||
else if(icu->adrcode & MA_MAP11) mtex= ma->mtex[10];
|
||||
else if(icu->adrcode & MA_MAP13) mtex= ma->mtex[12];
|
||||
else if(icu->adrcode & MA_MAP14) mtex= ma->mtex[13];
|
||||
else if(icu->adrcode & MA_MAP15) mtex= ma->mtex[14];
|
||||
else if(icu->adrcode & MA_MAP16) mtex= ma->mtex[15];
|
||||
else if(icu->adrcode & MA_MAP17) mtex= ma->mtex[16];
|
||||
else if(icu->adrcode & MA_MAP18) mtex= ma->mtex[17];
|
||||
|
||||
if(mtex) {
|
||||
poin= give_mtex_poin(mtex, icu->adrcode & (MA_MAP1-1) );
|
||||
@@ -1479,7 +1487,14 @@ void *get_ipo_poin(ID *id, IpoCurve *icu, int *type)
|
||||
else if(icu->adrcode & MA_MAP8) mtex= wo->mtex[7];
|
||||
else if(icu->adrcode & MA_MAP9) mtex= wo->mtex[8];
|
||||
else if(icu->adrcode & MA_MAP10) mtex= wo->mtex[9];
|
||||
|
||||
else if(icu->adrcode & MA_MAP11) mtex= wo->mtex[10];
|
||||
else if(icu->adrcode & MA_MAP12) mtex= wo->mtex[11];
|
||||
else if(icu->adrcode & MA_MAP13) mtex= wo->mtex[12];
|
||||
else if(icu->adrcode & MA_MAP14) mtex= wo->mtex[13];
|
||||
else if(icu->adrcode & MA_MAP15) mtex= wo->mtex[14];
|
||||
else if(icu->adrcode & MA_MAP16) mtex= wo->mtex[15];
|
||||
else if(icu->adrcode & MA_MAP17) mtex= wo->mtex[16];
|
||||
else if(icu->adrcode & MA_MAP18) mtex= wo->mtex[17];
|
||||
if(mtex) {
|
||||
poin= give_mtex_poin(mtex, icu->adrcode & (MA_MAP1-1) );
|
||||
}
|
||||
@@ -1524,6 +1539,14 @@ void *get_ipo_poin(ID *id, IpoCurve *icu, int *type)
|
||||
else if(icu->adrcode & MA_MAP8) mtex= la->mtex[7];
|
||||
else if(icu->adrcode & MA_MAP9) mtex= la->mtex[8];
|
||||
else if(icu->adrcode & MA_MAP10) mtex= la->mtex[9];
|
||||
else if(icu->adrcode & MA_MAP11) mtex= la->mtex[10];
|
||||
else if(icu->adrcode & MA_MAP12) mtex= la->mtex[11];
|
||||
else if(icu->adrcode & MA_MAP13) mtex= la->mtex[12];
|
||||
else if(icu->adrcode & MA_MAP14) mtex= la->mtex[13];
|
||||
else if(icu->adrcode & MA_MAP15) mtex= la->mtex[14];
|
||||
else if(icu->adrcode & MA_MAP16) mtex= la->mtex[15];
|
||||
else if(icu->adrcode & MA_MAP17) mtex= la->mtex[16];
|
||||
else if(icu->adrcode & MA_MAP18) mtex= la->mtex[17];
|
||||
|
||||
if(mtex) {
|
||||
poin= give_mtex_poin(mtex, icu->adrcode & (MA_MAP1-1) );
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
|
||||
#include "BPY_extern.h"
|
||||
|
||||
#include "GPU_material.h"
|
||||
|
||||
/* used in UI and render */
|
||||
Material defmaterial;
|
||||
|
||||
@@ -96,6 +98,9 @@ void free_material(Material *ma)
|
||||
ntreeFreeTree(ma->nodetree);
|
||||
MEM_freeN(ma->nodetree);
|
||||
}
|
||||
|
||||
if(ma->gpumaterial.first)
|
||||
GPU_material_free(ma);
|
||||
}
|
||||
|
||||
void init_material(Material *ma)
|
||||
@@ -207,6 +212,8 @@ Material *copy_material(Material *ma)
|
||||
if(ma->nodetree) {
|
||||
man->nodetree= ntreeCopyTree(ma->nodetree, 0); /* 0 == full new tree */
|
||||
}
|
||||
|
||||
man->gpumaterial.first= man->gpumaterial.last= NULL;
|
||||
|
||||
return man;
|
||||
}
|
||||
|
||||
@@ -79,45 +79,6 @@
|
||||
#include "BLI_editVert.h"
|
||||
#include "BLI_arithb.h"
|
||||
|
||||
int update_realtime_texture(MTFace *tface, double time)
|
||||
{
|
||||
Image *ima;
|
||||
int inc = 0;
|
||||
float diff;
|
||||
int newframe;
|
||||
|
||||
ima = tface->tpage;
|
||||
|
||||
if (!ima)
|
||||
return 0;
|
||||
|
||||
if (ima->lastupdate<0)
|
||||
ima->lastupdate = 0;
|
||||
|
||||
if (ima->lastupdate>time)
|
||||
ima->lastupdate=(float)time;
|
||||
|
||||
if(ima->tpageflag & IMA_TWINANIM) {
|
||||
if(ima->twend >= ima->xrep*ima->yrep) ima->twend= ima->xrep*ima->yrep-1;
|
||||
|
||||
/* check: is the bindcode not in the array? Then free. (still to do) */
|
||||
|
||||
diff = (float)(time-ima->lastupdate);
|
||||
|
||||
inc = (int)(diff*(float)ima->animspeed);
|
||||
|
||||
ima->lastupdate+=((float)inc/(float)ima->animspeed);
|
||||
|
||||
newframe = ima->lastframe+inc;
|
||||
|
||||
if (newframe > (int)ima->twend)
|
||||
newframe = (int)ima->twsta-1 + (newframe-ima->twend)%(ima->twend-ima->twsta);
|
||||
|
||||
ima->lastframe = newframe;
|
||||
}
|
||||
return inc;
|
||||
}
|
||||
|
||||
void mesh_update_customdata_pointers(Mesh *me)
|
||||
{
|
||||
me->mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
|
||||
|
||||
@@ -68,6 +68,9 @@
|
||||
|
||||
#include "SHD_node.h"
|
||||
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_material.h"
|
||||
|
||||
static ListBase empty_list = {NULL, NULL};
|
||||
ListBase node_all_composit = {NULL, NULL};
|
||||
ListBase node_all_shaders = {NULL, NULL};
|
||||
@@ -2352,6 +2355,117 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int do_preview)
|
||||
ntreeEndExecTree(ntree);
|
||||
}
|
||||
|
||||
/* GPU material from shader nodes */
|
||||
|
||||
static void gpu_from_node_stack(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs)
|
||||
{
|
||||
bNodeSocket *sock;
|
||||
int i;
|
||||
|
||||
for (sock=sockets->first, i=0; sock; sock=sock->next, i++) {
|
||||
memset(&gs[i], 0, sizeof(gs[i]));
|
||||
|
||||
QUATCOPY(gs[i].vec, ns[i]->vec);
|
||||
gs[i].link= ns[i]->data;
|
||||
|
||||
if (sock->type == SOCK_VALUE)
|
||||
gs[i].type= GPU_FLOAT;
|
||||
else if (sock->type == SOCK_VECTOR)
|
||||
gs[i].type= GPU_VEC3;
|
||||
else if (sock->type == SOCK_RGBA)
|
||||
gs[i].type= GPU_VEC4;
|
||||
else
|
||||
gs[i].type= GPU_NONE;
|
||||
|
||||
gs[i].name = "";
|
||||
gs[i].hasinput= ns[i]->hasinput;
|
||||
gs[i].hasoutput= ns[i]->hasinput;
|
||||
gs[i].sockettype= ns[i]->sockettype;
|
||||
}
|
||||
|
||||
gs[i].type= GPU_NONE;
|
||||
}
|
||||
|
||||
static void data_from_gpu_stack(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs)
|
||||
{
|
||||
bNodeSocket *sock;
|
||||
int i;
|
||||
|
||||
for (sock=sockets->first, i=0; sock; sock=sock->next, i++) {
|
||||
ns[i]->data= gs[i].link;
|
||||
ns[i]->hasinput= gs[i].hasinput;
|
||||
ns[i]->hasoutput= gs[i].hasoutput;
|
||||
ns[i]->sockettype= gs[i].sockettype;
|
||||
}
|
||||
}
|
||||
|
||||
static void gpu_node_group_execute(bNodeStack *stack, GPUMaterial *mat, bNode *gnode, bNodeStack **in, bNodeStack **out)
|
||||
{
|
||||
bNode *node;
|
||||
bNodeTree *ntree= (bNodeTree *)gnode->id;
|
||||
bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
|
||||
bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
|
||||
GPUNodeStack gpuin[MAX_SOCKET+1], gpuout[MAX_SOCKET+1];
|
||||
int doit = 0;
|
||||
|
||||
if(ntree==NULL) return;
|
||||
|
||||
stack+= gnode->stack_index;
|
||||
|
||||
for(node= ntree->nodes.first; node; node= node->next) {
|
||||
if(node->typeinfo->gpufunc) {
|
||||
group_node_get_stack(node, stack, nsin, nsout, in, out);
|
||||
|
||||
doit = 0;
|
||||
|
||||
/* for groups, only execute outputs for edited group */
|
||||
if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) {
|
||||
if(gnode->flag & NODE_GROUP_EDIT)
|
||||
if(node->flag & NODE_DO_OUTPUT)
|
||||
doit = 1;
|
||||
}
|
||||
else
|
||||
doit = 1;
|
||||
|
||||
if(doit) {
|
||||
gpu_from_node_stack(&node->inputs, nsin, gpuin);
|
||||
gpu_from_node_stack(&node->outputs, nsout, gpuout);
|
||||
if(node->typeinfo->gpufunc(mat, node, gpuin, gpuout))
|
||||
data_from_gpu_stack(&node->outputs, nsout, gpuout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat)
|
||||
{
|
||||
bNode *node;
|
||||
bNodeStack *stack;
|
||||
bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
|
||||
bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
|
||||
GPUNodeStack gpuin[MAX_SOCKET+1], gpuout[MAX_SOCKET+1];
|
||||
|
||||
if((ntree->init & NTREE_EXEC_INIT)==0)
|
||||
ntreeBeginExecTree(ntree);
|
||||
|
||||
stack= ntree->stack;
|
||||
|
||||
for(node= ntree->nodes.first; node; node= node->next) {
|
||||
if(node->typeinfo->gpufunc) {
|
||||
node_get_stack(node, stack, nsin, nsout);
|
||||
gpu_from_node_stack(&node->inputs, nsin, gpuin);
|
||||
gpu_from_node_stack(&node->outputs, nsout, gpuout);
|
||||
if(node->typeinfo->gpufunc(mat, node, gpuin, gpuout))
|
||||
data_from_gpu_stack(&node->outputs, nsout, gpuout);
|
||||
}
|
||||
else if(node->type==NODE_GROUP && node->id) {
|
||||
node_get_stack(node, stack, nsin, nsout);
|
||||
gpu_node_group_execute(stack, mat, node, nsin, nsout);
|
||||
}
|
||||
}
|
||||
|
||||
ntreeEndExecTree(ntree);
|
||||
}
|
||||
|
||||
/* **************** call to switch lamploop for material node ************ */
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@
|
||||
|
||||
#include "BPY_extern.h"
|
||||
|
||||
#include "GPU_material.h"
|
||||
|
||||
#include "blendef.h"
|
||||
|
||||
/* Local function protos */
|
||||
@@ -268,6 +270,7 @@ void free_object(Object *ob)
|
||||
}
|
||||
if(ob->soft) sbFree(ob->soft);
|
||||
if(ob->fluidsimSettings) fluidsimSettingsFree(ob->fluidsimSettings);
|
||||
if(ob->gpulamp.first) GPU_lamp_free(ob);
|
||||
}
|
||||
|
||||
static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin)
|
||||
@@ -918,7 +921,7 @@ Object *add_only_object(int type, char *name)
|
||||
QuatOne(ob->dquat);
|
||||
#endif
|
||||
|
||||
ob->col[0]= ob->col[1]= ob->col[2]= 0.0;
|
||||
ob->col[0]= ob->col[1]= ob->col[2]= 1.0;
|
||||
ob->col[3]= 1.0;
|
||||
|
||||
ob->loc[0]= ob->loc[1]= ob->loc[2]= 0.0;
|
||||
@@ -1226,6 +1229,7 @@ Object *copy_object(Object *ob)
|
||||
obn->vnode = NULL;
|
||||
#endif
|
||||
|
||||
obn->gpulamp.first = obn->gpulamp.last = NULL;
|
||||
|
||||
return obn;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@
|
||||
|
||||
#include "BIF_gl.h"
|
||||
|
||||
#include "GPU_draw.h"
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_material.h"
|
||||
|
||||
#include "CCGSubSurf.h"
|
||||
|
||||
typedef struct _VertData {
|
||||
@@ -1599,7 +1603,7 @@ static void ccgDM_glNormalFast(float *a, float *b, float *c, float *d)
|
||||
}
|
||||
|
||||
/* Only used by non-editmesh types */
|
||||
static void ccgDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int)) {
|
||||
static void ccgDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *attribs)) {
|
||||
CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
|
||||
CCGSubSurf *ss = ccgdm->ss;
|
||||
CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
|
||||
@@ -1621,7 +1625,7 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int)) {
|
||||
mat_nr= 0;
|
||||
}
|
||||
|
||||
if (!setMaterial(mat_nr+1))
|
||||
if (!setMaterial(mat_nr+1, NULL))
|
||||
continue;
|
||||
|
||||
glShadeModel(drawSmooth? GL_SMOOTH: GL_FLAT);
|
||||
@@ -1666,6 +1670,168 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int)) {
|
||||
|
||||
ccgFaceIterator_free(fi);
|
||||
}
|
||||
|
||||
/* Only used by non-editmesh types */
|
||||
static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs), int (*setDrawOptions)(void *userData, int index), void *userData) {
|
||||
CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
|
||||
CCGSubSurf *ss = ccgdm->ss;
|
||||
CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
|
||||
GPUVertexAttribs gattribs;
|
||||
DMVertexAttribs attribs;
|
||||
MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE);
|
||||
int gridSize = ccgSubSurf_getGridSize(ss);
|
||||
int gridFaces = gridSize - 1;
|
||||
int edgeSize = ccgSubSurf_getEdgeSize(ss);
|
||||
int transp, orig_transp, new_transp;
|
||||
char *faceFlags = DM_get_face_data_layer(dm, CD_FLAGS);
|
||||
int a, b, i, doDraw, numVerts, matnr, new_matnr, totface;
|
||||
|
||||
doDraw = 0;
|
||||
numVerts = 0;
|
||||
matnr = -1;
|
||||
transp = GPU_get_material_blend_mode();
|
||||
orig_transp = transp;
|
||||
|
||||
memset(&attribs, 0, sizeof(attribs));
|
||||
|
||||
#define PASSATTRIB(dx, dy, vert) { \
|
||||
if(attribs.totorco) { \
|
||||
index = getFaceIndex(ss, f, S, x+dx, y+dy, edgeSize, gridSize); \
|
||||
glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]); \
|
||||
} \
|
||||
for(b = 0; b < attribs.tottface; b++) { \
|
||||
MTFace *tf = &attribs.tface[b].array[a]; \
|
||||
glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]); \
|
||||
} \
|
||||
for(b = 0; b < attribs.totmcol; b++) { \
|
||||
MCol *cp = &attribs.mcol[b].array[a*4 + vert]; \
|
||||
GLubyte col[4]; \
|
||||
col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; \
|
||||
glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col); \
|
||||
} \
|
||||
if(attribs.tottang) { \
|
||||
float *tang = attribs.tang.array[a*4 + vert]; \
|
||||
glVertexAttrib3fvARB(attribs.tang.glIndex, tang); \
|
||||
} \
|
||||
}
|
||||
|
||||
totface = ccgSubSurf_getNumFaces(ss);
|
||||
for(a = 0, i = 0; i < totface; i++) {
|
||||
CCGFace *f = ccgdm->faceMap[i].face;
|
||||
int S, x, y, drawSmooth;
|
||||
int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(ss, f));
|
||||
int origIndex = ccgDM_getFaceMapIndex(ccgdm, ss, f);
|
||||
|
||||
numVerts = ccgSubSurf_getFaceNumVerts(ss, f);
|
||||
|
||||
if(faceFlags) {
|
||||
drawSmooth = (faceFlags[index*4] & ME_SMOOTH);
|
||||
new_matnr= faceFlags[index*4 + 1] + 1;
|
||||
}
|
||||
else {
|
||||
drawSmooth = 1;
|
||||
new_matnr= 1;
|
||||
}
|
||||
|
||||
if(new_matnr != matnr) {
|
||||
doDraw = setMaterial(matnr = new_matnr, &gattribs);
|
||||
if(doDraw)
|
||||
DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
|
||||
}
|
||||
|
||||
if(!doDraw || (setDrawOptions && !setDrawOptions(userData, origIndex))) {
|
||||
a += gridFaces*gridFaces*numVerts;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(tf) {
|
||||
new_transp = tf[i].transp;
|
||||
|
||||
if(new_transp != transp) {
|
||||
if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
|
||||
GPU_set_material_blend_mode(orig_transp);
|
||||
else
|
||||
GPU_set_material_blend_mode(new_transp);
|
||||
transp = new_transp;
|
||||
}
|
||||
}
|
||||
|
||||
glShadeModel(drawSmooth? GL_SMOOTH: GL_FLAT);
|
||||
for (S=0; S<numVerts; S++) {
|
||||
VertData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
|
||||
VertData *vda, *vdb;
|
||||
|
||||
if (drawSmooth) {
|
||||
for (y=0; y<gridFaces; y++) {
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (x=0; x<gridFaces; x++) {
|
||||
vda = &faceGridData[(y+0)*gridSize + x];
|
||||
vdb = &faceGridData[(y+1)*gridSize + x];
|
||||
|
||||
PASSATTRIB(0, 0, 0);
|
||||
glNormal3fv(vda->no);
|
||||
glVertex3fv(vda->co);
|
||||
|
||||
PASSATTRIB(0, 1, 1);
|
||||
glNormal3fv(vdb->no);
|
||||
glVertex3fv(vdb->co);
|
||||
|
||||
if(x != gridFaces-1)
|
||||
a++;
|
||||
}
|
||||
|
||||
vda = &faceGridData[(y+0)*gridSize + x];
|
||||
vdb = &faceGridData[(y+1)*gridSize + x];
|
||||
|
||||
PASSATTRIB(0, 0, 3);
|
||||
glNormal3fv(vda->no);
|
||||
glVertex3fv(vda->co);
|
||||
|
||||
PASSATTRIB(0, 1, 2);
|
||||
glNormal3fv(vdb->no);
|
||||
glVertex3fv(vdb->co);
|
||||
|
||||
glEnd();
|
||||
|
||||
a++;
|
||||
}
|
||||
} else {
|
||||
glBegin(GL_QUADS);
|
||||
for (y=0; y<gridFaces; y++) {
|
||||
for (x=0; x<gridFaces; x++) {
|
||||
float *aco = faceGridData[(y+0)*gridSize + x].co;
|
||||
float *bco = faceGridData[(y+0)*gridSize + x + 1].co;
|
||||
float *cco = faceGridData[(y+1)*gridSize + x + 1].co;
|
||||
float *dco = faceGridData[(y+1)*gridSize + x].co;
|
||||
|
||||
ccgDM_glNormalFast(aco, bco, cco, dco);
|
||||
|
||||
PASSATTRIB(0, 1, 1);
|
||||
glVertex3fv(dco);
|
||||
PASSATTRIB(1, 1, 2);
|
||||
glVertex3fv(cco);
|
||||
PASSATTRIB(1, 0, 3);
|
||||
glVertex3fv(bco);
|
||||
PASSATTRIB(0, 0, 0);
|
||||
glVertex3fv(aco);
|
||||
|
||||
a++;
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef PASSATTRIB
|
||||
|
||||
ccgFaceIterator_free(fi);
|
||||
}
|
||||
|
||||
static void ccgDM_drawFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs)) {
|
||||
dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
|
||||
}
|
||||
|
||||
static void ccgDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned char *col1, unsigned char *col2) {
|
||||
CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
|
||||
CCGSubSurf *ss = ccgdm->ss;
|
||||
@@ -2143,8 +2309,10 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
|
||||
ccgdm->dm.drawFacesSolid = ccgDM_drawFacesSolid;
|
||||
ccgdm->dm.drawFacesColored = ccgDM_drawFacesColored;
|
||||
ccgdm->dm.drawFacesTex = ccgDM_drawFacesTex;
|
||||
ccgdm->dm.drawFacesGLSL = ccgDM_drawFacesGLSL;
|
||||
ccgdm->dm.drawMappedFaces = ccgDM_drawMappedFaces;
|
||||
ccgdm->dm.drawMappedFacesTex = ccgDM_drawMappedFacesTex;
|
||||
ccgdm->dm.drawMappedFacesGLSL = ccgDM_drawMappedFacesGLSL;
|
||||
ccgdm->dm.drawUVEdges = ccgDM_drawUVEdges;
|
||||
|
||||
ccgdm->dm.drawMappedEdgesInterp = ccgDM_drawMappedEdgesInterp;
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_brush_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
#include "DNA_color_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
@@ -390,6 +391,17 @@ int do_colorband(ColorBand *coba, float in, float out[4])
|
||||
return 1; /* OK */
|
||||
}
|
||||
|
||||
void colorband_table_RGBA(ColorBand *coba, float **array, int *size)
|
||||
{
|
||||
int a;
|
||||
|
||||
*size = CM_TABLE+1;
|
||||
*array = MEM_callocN(sizeof(float)*(*size)*4, "ColorBand");
|
||||
|
||||
for(a=0; a<*size; a++)
|
||||
do_colorband(coba, (float)a/(float)CM_TABLE, &(*array)[a*4]);
|
||||
}
|
||||
|
||||
/* ******************* TEX ************************ */
|
||||
|
||||
void free_texture(Tex *tex)
|
||||
|
||||
@@ -260,6 +260,7 @@ void Vec2Mulf(float *v1, float f);
|
||||
void Vec2Addf(float *v, float *v1, float *v2);
|
||||
void Vec2Subf(float *v, float *v1, float *v2);
|
||||
void Vec2Copyf(float *v1, float *v2);
|
||||
void Vec2Lerpf(float *target, float *a, float *b, float t);
|
||||
|
||||
void AxisAngleToQuat(float *q, float *axis, float angle);
|
||||
void vectoquat(float *vec, short axis, short upflag, float *q);
|
||||
|
||||
@@ -73,7 +73,6 @@ extern ListBase fillvertbase;
|
||||
* @attention Defined in scanfill.c
|
||||
*/
|
||||
extern ListBase filledgebase;
|
||||
extern int totblock;
|
||||
|
||||
extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */
|
||||
|
||||
|
||||
@@ -2113,6 +2113,14 @@ void VecLerpf(float *target, float *a, float *b, float t)
|
||||
target[2]= s*a[2] + t*b[2];
|
||||
}
|
||||
|
||||
void Vec2Lerpf(float *target, float *a, float *b, float t)
|
||||
{
|
||||
float s = 1.0f-t;
|
||||
|
||||
target[0]= s*a[0] + t*b[0];
|
||||
target[1]= s*a[1] + t*b[1];
|
||||
}
|
||||
|
||||
void VecMidf(float *v, float *v1, float *v2)
|
||||
{
|
||||
v[0]= 0.5f*(v1[0]+ v2[0]);
|
||||
|
||||
@@ -1138,6 +1138,8 @@ void blo_make_image_pointer_map(FileData *fd)
|
||||
Link *ibuf= ima->ibufs.first;
|
||||
for(; ibuf; ibuf= ibuf->next)
|
||||
oldnewmap_insert(fd->imamap, ibuf, ibuf, 0);
|
||||
if(ima->gputexture)
|
||||
oldnewmap_insert(fd->imamap, ima->gputexture, ima->gputexture, 0);
|
||||
}
|
||||
for(; sce; sce= sce->id.next) {
|
||||
if(sce->nodetree) {
|
||||
@@ -1172,8 +1174,11 @@ void blo_end_image_pointer_map(FileData *fd)
|
||||
if(NULL==newimaadr(fd, ibuf)) { /* so was restored */
|
||||
BLI_remlink(&ima->ibufs, ibuf);
|
||||
ima->bindcode= 0;
|
||||
ima->gputexture= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ima->gputexture= newimaadr(fd, ima->gputexture);
|
||||
}
|
||||
for(; sce; sce= sce->id.next) {
|
||||
if(sce->nodetree) {
|
||||
@@ -2340,8 +2345,10 @@ static void direct_link_image(FileData *fd, Image *ima)
|
||||
ima->ibufs.first= ima->ibufs.last= NULL;
|
||||
|
||||
/* if not restored, we keep the binded opengl index */
|
||||
if(ima->ibufs.first==NULL)
|
||||
if(ima->ibufs.first==NULL) {
|
||||
ima->bindcode= 0;
|
||||
ima->gputexture= NULL;
|
||||
}
|
||||
|
||||
ima->anim= NULL;
|
||||
ima->rr= NULL;
|
||||
@@ -2552,6 +2559,7 @@ static void direct_link_material(FileData *fd, Material *ma)
|
||||
direct_link_nodetree(fd, ma->nodetree);
|
||||
|
||||
ma->preview = direct_link_preview_image(fd, ma->preview);
|
||||
ma->gpumaterial.first = ma->gpumaterial.last = NULL;
|
||||
}
|
||||
|
||||
/* ************ READ PARTICLE SETTINGS ***************** */
|
||||
@@ -3390,6 +3398,7 @@ static void direct_link_object(FileData *fd, Object *ob)
|
||||
ob->bb= NULL;
|
||||
ob->derivedDeform= NULL;
|
||||
ob->derivedFinal= NULL;
|
||||
ob->gpulamp.first= ob->gpulamp.last= NULL;
|
||||
}
|
||||
|
||||
/* ************ READ SCENE ***************** */
|
||||
|
||||
34
source/blender/gpu/CMakeLists.txt
Normal file
34
source/blender/gpu/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
# $Id: CMakeLists.txt 14444 2008-04-16 22:40:48Z hos $
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2006, Blender Foundation
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): Jacques Beaurain.
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
FILE(GLOB SRC intern/*.c)
|
||||
|
||||
SET(INC
|
||||
. ../blenlib ../blenkernel ../makesdna ../include
|
||||
../../../extern/glew/include ../../../intern/guardedalloc ../imbuf)
|
||||
|
||||
BLENDERLIB(bf_gpu "${SRC}" "${INC}")
|
||||
|
||||
116
source/blender/gpu/GPU_draw.h
Normal file
116
source/blender/gpu/GPU_draw.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This shader 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 shader 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 shader; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* 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 *****
|
||||
*/
|
||||
|
||||
#ifndef GPU_GAME_H
|
||||
#define GPU_GAME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct MTFace;
|
||||
struct Image;
|
||||
struct Scene;
|
||||
struct Object;
|
||||
|
||||
/* OpenGL drawing functions related to shading. These are also
|
||||
* shared with the game engine, where there were previously
|
||||
* duplicates of some of these functions. */
|
||||
|
||||
/* Initialize
|
||||
* - sets the default Blender opengl state, if in doubt, check
|
||||
* the contents of this function
|
||||
* - this is called when starting Blender, for opengl rendering,
|
||||
* and for switching back from the game engine for example. */
|
||||
|
||||
void GPU_state_init(void);
|
||||
|
||||
/* Material drawing
|
||||
* - first the state is initialized by a particular object and
|
||||
* it's materials
|
||||
* - after this, materials can be quickly enabled by their number,
|
||||
* GPU_enable_material returns 0 if drawing should be skipped
|
||||
* - after drawing, the material must be disabled again */
|
||||
|
||||
void GPU_set_object_materials(struct Scene *scene, struct Object *ob,
|
||||
int glsl, int *do_alpha_pass);
|
||||
int GPU_enable_material(int nr, void *attribs);
|
||||
void GPU_disable_material(void);
|
||||
|
||||
void GPU_set_material_blend_mode(int blendmode);
|
||||
int GPU_get_material_blend_mode(void);
|
||||
|
||||
/* TexFace drawing
|
||||
* - this is mutually exclusive with material drawing, a mesh should
|
||||
* be drawn using one or the other
|
||||
* - passing NULL clears the state again */
|
||||
|
||||
int GPU_set_tpage(struct MTFace *tface);
|
||||
|
||||
/* Lights
|
||||
* - returns how many lights were enabled
|
||||
* - this affects fixed functions materials and texface, not glsl */
|
||||
|
||||
int GPU_default_lights(void);
|
||||
int GPU_scene_object_lights(struct Scene *scene, struct Object *ob,
|
||||
int lay, float viewmat[][4]);
|
||||
|
||||
/* Text render
|
||||
* - based on moving uv coordinates */
|
||||
|
||||
void GPU_render_text(struct MTFace *tface, int mode,
|
||||
const char *textstr, int textlen, unsigned int *col,
|
||||
float *v1, float *v2, float *v3, float *v4, int glattrib);
|
||||
|
||||
/* Mipmap settings
|
||||
* - these will free textures on changes */
|
||||
|
||||
void GPU_set_mipmap(int mipmap);
|
||||
void GPU_set_linear_mipmap(int linear);
|
||||
void GPU_paint_set_mipmap(int mipmap);
|
||||
|
||||
/* Image updates and free
|
||||
* - these deal with images bound as opengl textures */
|
||||
|
||||
void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h);
|
||||
void GPU_update_images_framechange(void);
|
||||
int GPU_update_image_time(struct Image *ima, double time);
|
||||
int GPU_verify_image(struct Image *ima, int tftile, int tfmode, int compare);
|
||||
void GPU_free_image(struct Image *ima);
|
||||
void GPU_free_images(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
144
source/blender/gpu/GPU_extensions.h
Normal file
144
source/blender/gpu/GPU_extensions.h
Normal file
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This shader 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 shader 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 shader; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* 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 *****
|
||||
*/
|
||||
|
||||
#ifndef GPU_EXTENSIONS_H
|
||||
#define GPU_EXTENSIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* GPU extensions support */
|
||||
|
||||
struct Image;
|
||||
struct ImageUser;
|
||||
|
||||
struct GPUTexture;
|
||||
typedef struct GPUTexture GPUTexture;
|
||||
|
||||
struct GPUFrameBuffer;
|
||||
typedef struct GPUFrameBuffer GPUFrameBuffer;
|
||||
|
||||
struct GPUShader;
|
||||
typedef struct GPUShader GPUShader;
|
||||
|
||||
void GPU_extensions_init(void); /* call this before running any of the functions below */
|
||||
void GPU_extensions_exit(void);
|
||||
int GPU_extensions_minimum_support(void);
|
||||
int GPU_print_error(char *str);
|
||||
|
||||
/* GPU Texture
|
||||
- always returns unsigned char RGBA textures
|
||||
- if texture with non square dimensions is created, depending on the
|
||||
graphics card capabilities the texture may actually be stored in a
|
||||
larger texture with power of two dimensions. the actual dimensions
|
||||
may be querd with GPU_texture_opengl_width/height. GPU_texture_coord_2f
|
||||
calls glTexCoord2f with the coordinates adjust for this.
|
||||
- can use reference counting:
|
||||
- reference counter after GPU_texture_create is 1
|
||||
- GPU_texture_ref increases by one
|
||||
- GPU_texture_free decreases by one, and frees if 0
|
||||
- if created with from_blender, will not free the texture
|
||||
*/
|
||||
|
||||
GPUTexture *GPU_texture_create_1D(int w, float *pixels);
|
||||
GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels);
|
||||
GPUTexture *GPU_texture_create_depth(int w, int h);
|
||||
GPUTexture *GPU_texture_from_blender(struct Image *ima,
|
||||
struct ImageUser *iuser, double time);
|
||||
void GPU_texture_free(GPUTexture *tex);
|
||||
|
||||
void GPU_texture_ref(GPUTexture *tex);
|
||||
|
||||
void GPU_texture_bind(GPUTexture *tex, int number);
|
||||
void GPU_texture_unbind(GPUTexture *tex);
|
||||
|
||||
GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
|
||||
|
||||
int GPU_texture_target(GPUTexture *tex);
|
||||
int GPU_texture_opengl_width(GPUTexture *tex);
|
||||
int GPU_texture_opengl_height(GPUTexture *tex);
|
||||
|
||||
/* GPU Framebuffer
|
||||
- this is a wrapper for an OpenGL framebuffer object (FBO). in practice
|
||||
multiple FBO's may be created, to get around limitations on the number
|
||||
of attached textures and the dimension requirements.
|
||||
- after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must
|
||||
be called before rendering to the window framebuffer again */
|
||||
|
||||
GPUFrameBuffer *GPU_framebuffer_create();
|
||||
int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex);
|
||||
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex);
|
||||
void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex);
|
||||
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
|
||||
void GPU_framebuffer_free(GPUFrameBuffer *fb);
|
||||
|
||||
void GPU_framebuffer_restore();
|
||||
|
||||
/* GPU Shader
|
||||
- only for fragment shaders now
|
||||
- must call texture bind before setting a texture as uniform! */
|
||||
|
||||
GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, GPUShader *lib);
|
||||
GPUShader *GPU_shader_create_lib(const char *code);
|
||||
void GPU_shader_free(GPUShader *shader);
|
||||
|
||||
void GPU_shader_bind(GPUShader *shader);
|
||||
void GPU_shader_unbind();
|
||||
|
||||
int GPU_shader_get_uniform(GPUShader *shader, char *name);
|
||||
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
|
||||
int arraysize, float *value);
|
||||
void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex);
|
||||
|
||||
int GPU_shader_get_attribute(GPUShader *shader, char *name);
|
||||
|
||||
/* Vertex attributes for shaders */
|
||||
|
||||
#define GPU_MAX_ATTRIB 32
|
||||
|
||||
typedef struct GPUVertexAttribs {
|
||||
struct {
|
||||
int type;
|
||||
int glindex;
|
||||
char name[32];
|
||||
} layer[GPU_MAX_ATTRIB];
|
||||
|
||||
int totlayer;
|
||||
} GPUVertexAttribs;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
169
source/blender/gpu/GPU_material.h
Normal file
169
source/blender/gpu/GPU_material.h
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This shader 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 shader 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 shader; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* 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 *****
|
||||
*/
|
||||
|
||||
#ifndef __GPU_MATERIAL__
|
||||
#define __GPU_MATERIAL__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Image;
|
||||
struct ImageUser;
|
||||
struct Material;
|
||||
struct Object;
|
||||
struct Lamp;
|
||||
struct bNode;
|
||||
struct LinkNode;
|
||||
struct Scene;
|
||||
struct GPUVertexAttribs;
|
||||
struct GPUNode;
|
||||
struct GPUNodeLink;
|
||||
struct GPUNodeStack;
|
||||
struct GPUMaterial;
|
||||
struct GPUTexture;
|
||||
struct GPULamp;
|
||||
|
||||
typedef struct GPUNode GPUNode;
|
||||
typedef struct GPUNodeLink GPUNodeLink;
|
||||
typedef struct GPUMaterial GPUMaterial;
|
||||
typedef struct GPULamp GPULamp;
|
||||
|
||||
/* Functions to create GPU Materials nodes */
|
||||
|
||||
typedef enum GPUType {
|
||||
GPU_NONE = 0,
|
||||
GPU_FLOAT = 1,
|
||||
GPU_VEC2 = 2,
|
||||
GPU_VEC3 = 3,
|
||||
GPU_VEC4 = 4,
|
||||
GPU_MAT3 = 9,
|
||||
GPU_MAT4 = 16,
|
||||
GPU_TEX1D = 1001,
|
||||
GPU_TEX2D = 1002,
|
||||
GPU_SHADOW2D = 1003,
|
||||
GPU_ATTRIB = 3001
|
||||
} GPUType;
|
||||
|
||||
typedef enum GPUBuiltin {
|
||||
GPU_VIEW_MATRIX = 1,
|
||||
GPU_OBJECT_MATRIX = 2,
|
||||
GPU_INVERSE_VIEW_MATRIX = 4,
|
||||
GPU_INVERSE_OBJECT_MATRIX = 8,
|
||||
GPU_VIEW_POSITION = 16,
|
||||
GPU_VIEW_NORMAL = 32,
|
||||
GPU_OBCOLOR = 64
|
||||
} GPUBuiltin;
|
||||
|
||||
typedef enum GPUBlendMode {
|
||||
GPU_BLEND_SOLID = 0,
|
||||
GPU_BLEND_ADD = 1,
|
||||
GPU_BLEND_ALPHA = 2,
|
||||
GPU_BLEND_CLIP = 4
|
||||
} GPUBlendMode;
|
||||
|
||||
typedef struct GPUNodeStack {
|
||||
GPUType type;
|
||||
char *name;
|
||||
float vec[4];
|
||||
struct GPUNodeLink *link;
|
||||
short hasinput;
|
||||
short hasoutput;
|
||||
short sockettype;
|
||||
} GPUNodeStack;
|
||||
|
||||
GPUNodeLink *GPU_attribute(int type, char *name);
|
||||
GPUNodeLink *GPU_uniform(float *num);
|
||||
GPUNodeLink *GPU_dynamic_uniform(float *num);
|
||||
GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
|
||||
GPUNodeLink *GPU_texture(int size, float *pixels);
|
||||
GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex);
|
||||
GPUNodeLink *GPU_socket(GPUNodeStack *sock);
|
||||
GPUNodeLink *GPU_builtin(GPUBuiltin builtin);
|
||||
|
||||
int GPU_link(GPUMaterial *mat, char *name, ...);
|
||||
int GPU_stack_link(GPUMaterial *mat, char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
|
||||
|
||||
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
|
||||
void GPU_material_enable_alpha(GPUMaterial *material);
|
||||
GPUBlendMode GPU_material_blend_mode(GPUMaterial *material, float obcol[4]);
|
||||
|
||||
/* High level functions to create and use GPU materials */
|
||||
|
||||
GPUMaterial *GPU_material_from_blender(struct Scene *scene, struct Material *ma);
|
||||
void GPU_material_free(struct Material *ma);
|
||||
|
||||
void GPU_materials_free();
|
||||
|
||||
void GPU_material_bind(GPUMaterial *material, int lay, double time);
|
||||
void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4]);
|
||||
void GPU_material_unbind(GPUMaterial *material);
|
||||
int GPU_material_bound(GPUMaterial *material);
|
||||
|
||||
void GPU_material_vertex_attributes(GPUMaterial *material,
|
||||
struct GPUVertexAttribs *attrib);
|
||||
|
||||
/* Exported shading */
|
||||
|
||||
typedef struct GPUShadeInput {
|
||||
GPUMaterial *gpumat;
|
||||
struct Material *mat;
|
||||
|
||||
GPUNodeLink *rgb, *specrgb, *vn, *view, *vcol, *ref;
|
||||
GPUNodeLink *alpha, *refl, *spec, *emit, *har, *amb;
|
||||
} GPUShadeInput;
|
||||
|
||||
typedef struct GPUShadeResult {
|
||||
GPUNodeLink *diff, *spec, *combined, *alpha;
|
||||
} GPUShadeResult;
|
||||
|
||||
void GPU_shadeinput_set(GPUMaterial *mat, struct Material *ma, GPUShadeInput *shi);
|
||||
void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr);
|
||||
|
||||
/* Lamps */
|
||||
|
||||
GPULamp *GPU_lamp_from_blender(struct Scene *scene, struct Object *ob, struct Object *par);
|
||||
void GPU_lamp_free(struct Object *ob);
|
||||
|
||||
int GPU_lamp_has_shadow_buffer(GPULamp *lamp);
|
||||
void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize, float winmat[][4]);
|
||||
void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp);
|
||||
|
||||
void GPU_lamp_update(GPULamp *lamp, float obmat[][4]);
|
||||
int GPU_lamp_shadow_layer(GPULamp *lamp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__GPU_MATERIAL__*/
|
||||
|
||||
37
source/blender/gpu/Makefile
Normal file
37
source/blender/gpu/Makefile
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL/BL DUAL 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,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): none yet.
|
||||
#
|
||||
# ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
#
|
||||
# Makes module object directory and bounces make to subdirectories.
|
||||
|
||||
SOURCEDIR = source/blender/gpu
|
||||
DIRS = intern
|
||||
|
||||
include nan_subdirs.mk
|
||||
11
source/blender/gpu/SConscript
Normal file
11
source/blender/gpu/SConscript
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
Import ('env')
|
||||
|
||||
sources = env.Glob('intern/*.c')
|
||||
|
||||
incs = '../blenlib ../blenkernel ../makesdna ../include'
|
||||
incs += ' #/extern/glew/include #intern/guardedalloc ../imbuf .'
|
||||
|
||||
incs += ' ' + env['BF_OPENGL_INC']
|
||||
|
||||
env.BlenderLib ( 'bf_gpu', sources, Split(incs), [], libtype=['core', 'player'], priority=[65, 20] )
|
||||
53
source/blender/gpu/intern/Makefile
Normal file
53
source/blender/gpu/intern/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL/BL DUAL 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,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): none yet.
|
||||
#
|
||||
# ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
#
|
||||
|
||||
LIBNAME = gpu
|
||||
DIR = $(OCGDIR)/blender/$(LIBNAME)
|
||||
|
||||
include nan_compile.mk
|
||||
|
||||
ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows"))
|
||||
CFLAGS += -funsigned-char
|
||||
endif
|
||||
|
||||
CFLAGS += $(LEVEL_1_C_WARNINGS)
|
||||
|
||||
CPPFLAGS += -I$(OPENGL_HEADERS)
|
||||
|
||||
CPPFLAGS += -I../../blenlib
|
||||
CPPFLAGS += -I../../makesdna
|
||||
CPPFLAGS += -I../../imbuf
|
||||
CPPFLAGS += -I../../blenkernel
|
||||
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += -I../
|
||||
|
||||
1439
source/blender/gpu/intern/gpu_codegen.c
Normal file
1439
source/blender/gpu/intern/gpu_codegen.c
Normal file
File diff suppressed because it is too large
Load Diff
87
source/blender/gpu/intern/gpu_codegen.h
Normal file
87
source/blender/gpu/intern/gpu_codegen.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* $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,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* 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 *****
|
||||
*/
|
||||
|
||||
#ifndef __GPU_CODEGEN_H__
|
||||
#define __GPU_CODEGEN_H__
|
||||
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
struct ListBase;
|
||||
struct GPUShader;
|
||||
struct GPUOutput;
|
||||
struct GPUNode;
|
||||
struct GPUVertexAttribs;
|
||||
|
||||
#define MAX_FUNCTION_NAME 64
|
||||
#define MAX_PARAMETER 32
|
||||
|
||||
#define FUNCTION_QUAL_IN 0
|
||||
#define FUNCTION_QUAL_OUT 1
|
||||
#define FUNCTION_QUAL_INOUT 2
|
||||
|
||||
typedef struct GPUFunction {
|
||||
char name[MAX_FUNCTION_NAME];
|
||||
int paramtype[MAX_PARAMETER];
|
||||
int paramqual[MAX_PARAMETER];
|
||||
int totparam;
|
||||
} GPUFunction;
|
||||
|
||||
GPUFunction *GPU_lookup_function(char *name);
|
||||
|
||||
/* Pass Generation
|
||||
- Takes a list of nodes and a desired output, and makes a pass. This
|
||||
will take ownership of the nodes and free them early if unused or
|
||||
at the end if used.
|
||||
*/
|
||||
|
||||
struct GPUPass;
|
||||
typedef struct GPUPass GPUPass;
|
||||
|
||||
GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink,
|
||||
struct GPUVertexAttribs *attribs, int *builtin, const char *name);
|
||||
|
||||
struct GPUShader *GPU_pass_shader(GPUPass *pass);
|
||||
|
||||
void GPU_pass_bind(GPUPass *pass, double time);
|
||||
void GPU_pass_update_uniforms(GPUPass *pass);
|
||||
void GPU_pass_unbind(GPUPass *pass);
|
||||
|
||||
void GPU_pass_free(GPUPass *pass);
|
||||
|
||||
/* Material calls */
|
||||
|
||||
char *GPU_builtin_name(GPUBuiltin builtin);
|
||||
void gpu_material_add_node(struct GPUMaterial *material, struct GPUNode *node);
|
||||
int GPU_link_changed(struct GPUNodeLink *link);
|
||||
|
||||
#endif
|
||||
|
||||
1167
source/blender/gpu/intern/gpu_draw.c
Normal file
1167
source/blender/gpu/intern/gpu_draw.c
Normal file
File diff suppressed because it is too large
Load Diff
987
source/blender/gpu/intern/gpu_extensions.c
Normal file
987
source/blender/gpu/intern/gpu_extensions.c
Normal file
@@ -0,0 +1,987 @@
|
||||
/**
|
||||
* $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,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* 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_listBase.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_global.h"
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#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
|
||||
*/
|
||||
|
||||
struct GPUGlobal {
|
||||
GLint maxtextures;
|
||||
GLuint currentfb;
|
||||
int minimumsupport;
|
||||
} GG = {1, 0, 0};
|
||||
|
||||
void GPU_extensions_init()
|
||||
{
|
||||
glewInit();
|
||||
|
||||
/* glewIsSupported("GL_VERSION_2_0") */
|
||||
|
||||
if (GLEW_ARB_multitexture)
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures);
|
||||
|
||||
GG.minimumsupport = 1;
|
||||
if (!GLEW_ARB_multitexture) GG.minimumsupport = 0;
|
||||
if (!GLEW_ARB_vertex_shader) GG.minimumsupport = 0;
|
||||
if (!GLEW_ARB_fragment_shader) GG.minimumsupport = 0;
|
||||
}
|
||||
|
||||
int GPU_extensions_minimum_support()
|
||||
{
|
||||
return GG.minimumsupport;
|
||||
}
|
||||
|
||||
int GPU_print_error(char *str)
|
||||
{
|
||||
GLenum errCode;
|
||||
|
||||
if (G.f & G_DEBUG) {
|
||||
if ((errCode = glGetError()) != GL_NO_ERROR) {
|
||||
fprintf(stderr, "%s opengl error: %s\n", str, gluErrorString(errCode));
|
||||
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? */
|
||||
};
|
||||
|
||||
#define FTOCHAR(val) val<=0.0f?0: (val>=1.0f?255: (char)(255.0f*val))
|
||||
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;
|
||||
}
|
||||
|
||||
if (!GLEW_ARB_texture_non_power_of_two) {
|
||||
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;
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time)
|
||||
{
|
||||
GPUTexture *tex;
|
||||
GLint w, h, border, lastbindcode, bindcode;
|
||||
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
|
||||
|
||||
GPU_update_image_time(ima, time);
|
||||
bindcode = GPU_verify_image(ima, 0, 0, 0);
|
||||
|
||||
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);
|
||||
glReadBuffer(GL_NONE);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex)
|
||||
{
|
||||
/* 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();
|
||||
}
|
||||
|
||||
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
};
|
||||
|
||||
static void shader_print_errors(char *task, char *log, const char *code)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, GPUShader *lib)
|
||||
{
|
||||
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");
|
||||
|
||||
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(lib && lib->lib)
|
||||
glAttachObjectARB(shader->object, lib->lib);
|
||||
|
||||
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) {
|
||||
glValidateProgramARB(shader->vertex);
|
||||
glGetInfoLogARB(shader->vertex, sizeof(log), &length, log);
|
||||
shader_print_errors("compile", log, vertexcode);
|
||||
|
||||
GPU_shader_free(shader);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(fragcode) {
|
||||
glAttachObjectARB(shader->object, shader->fragment);
|
||||
glShaderSourceARB(shader->fragment, 1, (const char**)&fragcode, NULL);
|
||||
|
||||
glCompileShaderARB(shader->fragment);
|
||||
glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
||||
|
||||
if (!status) {
|
||||
glValidateProgramARB(shader->fragment);
|
||||
glGetInfoLogARB(shader->fragment, sizeof(log), &length, log);
|
||||
shader_print_errors("compile", log, fragcode);
|
||||
|
||||
GPU_shader_free(shader);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
glLinkProgramARB(shader->object);
|
||||
glGetObjectParameterivARB(shader->object, GL_OBJECT_LINK_STATUS_ARB, &status);
|
||||
if (!status) {
|
||||
glGetInfoLogARB(shader->object, sizeof(log), &length, log);
|
||||
shader_print_errors("linking", log, fragcode);
|
||||
|
||||
GPU_shader_free(shader);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
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) {
|
||||
glValidateProgramARB(shader->lib);
|
||||
glGetInfoLogARB(shader->lib, sizeof(log), &length, log);
|
||||
shader_print_errors("compile", log, code);
|
||||
|
||||
GPU_shader_free(shader);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
void GPU_shader_bind(GPUShader *shader)
|
||||
{
|
||||
GPU_print_error("Pre Shader Bind");
|
||||
glUseProgramObjectARB(shader->object);
|
||||
GPU_print_error("Post Shader Bind");
|
||||
}
|
||||
|
||||
void GPU_shader_unbind()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
int GPU_shader_get_uniform(GPUShader *shader, char *name)
|
||||
{
|
||||
return glGetUniformLocationARB(shader->object, name);
|
||||
}
|
||||
|
||||
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, int arraysize, float *value)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex)
|
||||
{
|
||||
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;
|
||||
|
||||
glGenBuffersARB(pb->numbuffers, pb->bindcode);
|
||||
|
||||
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;
|
||||
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
||||
|
||||
for (i = 0; i < pb->numbuffers; i++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
|
||||
}
|
||||
|
||||
static int pixelbuffer_map_into_gpu(GLuint bindcode)
|
||||
{
|
||||
void *pixels;
|
||||
|
||||
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
||||
pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
|
||||
|
||||
/* do stuff in pixels */
|
||||
|
||||
if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
|
||||
fprintf(stderr, "Could not unmap opengl PBO\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
|
||||
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h,
|
||||
GL_RGBA, type, NULL);
|
||||
|
||||
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
1460
source/blender/gpu/intern/gpu_material.c
Normal file
1460
source/blender/gpu/intern/gpu_material.c
Normal file
File diff suppressed because it is too large
Load Diff
1543
source/blender/gpu/intern/gpu_shader_material.glsl
Normal file
1543
source/blender/gpu/intern/gpu_shader_material.glsl
Normal file
File diff suppressed because it is too large
Load Diff
1026
source/blender/gpu/intern/gpu_shader_material.glsl.c
Normal file
1026
source/blender/gpu/intern/gpu_shader_material.glsl.c
Normal file
File diff suppressed because it is too large
Load Diff
12
source/blender/gpu/intern/gpu_shader_vertex.glsl
Normal file
12
source/blender/gpu/intern/gpu_shader_vertex.glsl
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
varying vec3 varposition;
|
||||
varying vec3 varnormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 co = gl_ModelViewMatrix * gl_Vertex;
|
||||
|
||||
varposition = co.xyz;
|
||||
varnormal = gl_NormalMatrix * gl_Normal;
|
||||
gl_Position = gl_ProjectionMatrix * co;
|
||||
|
||||
13
source/blender/gpu/intern/gpu_shader_vertex.glsl.c
Normal file
13
source/blender/gpu/intern/gpu_shader_vertex.glsl.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* DataToC output of file <gpu_shader_vertex_glsl> */
|
||||
|
||||
int datatoc_gpu_shader_vertex_glsl_size= 217;
|
||||
char datatoc_gpu_shader_vertex_glsl[]= {
|
||||
10,118, 97,114,121,105,110,103, 32,118,101, 99, 51, 32,118, 97,114,112,111,115,105,116,105,111,110,
|
||||
59, 10,118, 97,114,121,105,110,103, 32,118,101, 99, 51, 32,118, 97,114,110,111,114,109, 97,108, 59, 10, 10,118,111,105,100, 32,
|
||||
109, 97,105,110, 40, 41, 10,123, 10, 9,118,101, 99, 52, 32, 99,111, 32, 61, 32,103,108, 95, 77,111,100,101,108, 86,105,101,119,
|
||||
77, 97,116,114,105,120, 32, 42, 32,103,108, 95, 86,101,114,116,101,120, 59, 10, 10, 9,118, 97,114,112,111,115,105,116,105,111,
|
||||
110, 32, 61, 32, 99,111, 46,120,121,122, 59, 10, 9,118, 97,114,110,111,114,109, 97,108, 32, 61, 32,103,108, 95, 78,111,114,109,
|
||||
97,108, 77, 97,116,114,105,120, 32, 42, 32,103,108, 95, 78,111,114,109, 97,108, 59, 10, 9,103,108, 95, 80,111,115,105,116,105,
|
||||
111,110, 32, 61, 32,103,108, 95, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 32, 42, 32, 99,111, 59, 10, 10,
|
||||
};
|
||||
|
||||
@@ -30,52 +30,11 @@
|
||||
#ifndef BDR_DRAWMESH_H
|
||||
#define BDR_DRAWMESH_H
|
||||
|
||||
struct Image;
|
||||
struct MTFace;
|
||||
struct Object;
|
||||
struct DerivedMesh;
|
||||
struct Mesh;
|
||||
struct EdgeHash;
|
||||
|
||||
/**
|
||||
* Enables or disable mipmapping for realtime images (textures).
|
||||
* Note that this will will destroy all texture bindings in OpenGL.
|
||||
* @see free_realtime_image()
|
||||
* @param mipmap Turn mipmapping on (mipmap!=0) or off (mipmap==0).
|
||||
*/
|
||||
void set_mipmap(int mipmap);
|
||||
|
||||
/**
|
||||
* Enables or disable linear mipmap setting for realtime images (textures).
|
||||
* Note that this will will destroy all texture bindings in OpenGL.
|
||||
* @see free_realtime_image()
|
||||
* @param mipmap Turn linear mipmapping on (linear!=0) or off (linear==0).
|
||||
*/
|
||||
void set_linear_mipmap(int linear);
|
||||
|
||||
/**
|
||||
* Returns the current setting for linear mipmapping.
|
||||
*/
|
||||
int get_linear_mipmap(void);
|
||||
|
||||
/**
|
||||
* Resets the realtime image cache variables.
|
||||
*/
|
||||
void clear_realtime_image_cache(void);
|
||||
|
||||
|
||||
void update_realtime_image(struct Image *ima, int x, int y, int w, int h);
|
||||
void free_realtime_image(struct Image *ima);
|
||||
void free_all_realtime_images(void);
|
||||
void make_repbind(struct Image *ima);
|
||||
int set_tpage(struct MTFace *tface);
|
||||
|
||||
void texpaint_enable_mipmap(void);
|
||||
void texpaint_disable_mipmap(void);
|
||||
|
||||
void draw_mesh_textured(struct Object *ob, struct DerivedMesh *dm, int facesel);
|
||||
struct EdgeHash *get_tface_mesh_marked_edge_info(struct Mesh *me);
|
||||
void init_realtime_GL(void);
|
||||
void draw_mesh_text(struct Object *ob, int glsl);
|
||||
|
||||
#endif /* BDR_DRAWMESH_H */
|
||||
|
||||
|
||||
@@ -47,8 +47,7 @@ struct EditVert;
|
||||
struct EditFace;
|
||||
struct EditEdge;
|
||||
|
||||
int set_gl_material(int nr);
|
||||
int init_gl_materials(struct Object *ob, int check_alpha);
|
||||
int draw_glsl_material(struct Object *ob, int dt);
|
||||
|
||||
void mesh_foreachScreenVert(void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts);
|
||||
void mesh_foreachScreenEdge(void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts);
|
||||
|
||||
@@ -34,8 +34,8 @@ void imagepaint_redraw_tool(void);
|
||||
void imagepaint_pick(short mousebutton);
|
||||
void imagepaint_paint(short mousebutton, short texturepaint);
|
||||
|
||||
void imagepaint_undo();
|
||||
void free_imagepaint();
|
||||
void undo_imagepaint_step(int step);
|
||||
void undo_imagepaint_clear(void);
|
||||
|
||||
#endif /* BDR_IMAGEPAINT_H */
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
struct ScrArea;
|
||||
struct SpaceText;
|
||||
struct Text;
|
||||
struct TextLine;
|
||||
|
||||
void unlink_text(struct Text *text);
|
||||
|
||||
|
||||
@@ -49,20 +49,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#else
|
||||
/* #if defined (__sun) || defined (__sun__)
|
||||
#include <GL/gl.h>
|
||||
#include <mesa/glu.h>
|
||||
#else
|
||||
*/
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
/* #endif */
|
||||
#endif
|
||||
|
||||
#include "GL/glew.h"
|
||||
|
||||
/*
|
||||
* these should be phased out. cpack should be replaced in
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#ifndef BIF_MESHTOOLS_H
|
||||
#define BIF_MESHTOOLS_H
|
||||
|
||||
#include "BLO_sys_types.h"
|
||||
|
||||
struct Object;
|
||||
struct EditVert;
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ struct rctf;
|
||||
struct ScrArea;
|
||||
struct ImBuf;
|
||||
|
||||
void default_gl_light(void);
|
||||
void init_gl_stuff(void);
|
||||
void circf(float x, float y, float rad);
|
||||
void circ(float x, float y, float rad);
|
||||
|
||||
@@ -55,8 +53,8 @@ struct ImBuf *read_backbuf(short xmin, short ymin, short xmax, short ymax);
|
||||
unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int min, unsigned int max, int *dist, short strict, unsigned int (*indextest)(unsigned int index));
|
||||
|
||||
void drawview3dspace(struct ScrArea *sa, void *spacedata);
|
||||
void drawview3d_render(struct View3D *v3d, int winx, int winy, float winmat[][4]);
|
||||
void draw_depth(struct ScrArea *sa, void *spacedata);
|
||||
void drawview3d_render(struct View3D *v3d, float viewmat[][4], int winx, int winy, float winmat[][4], int shadow);
|
||||
void draw_depth(struct ScrArea *sa, void *spacedata, int (*func)(void *) );
|
||||
void view3d_update_depths(struct View3D *v3d);
|
||||
|
||||
int update_time(int cfra);
|
||||
|
||||
@@ -300,6 +300,7 @@ typedef struct FreeCamera {
|
||||
#define ACT_NEW 4
|
||||
#define ACT_LINKED 8
|
||||
#define ACT_VISIBLE 16
|
||||
#define ACT_PIN 32
|
||||
|
||||
/* link codes */
|
||||
#define LINK_SENSOR 0
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "DNA_ID.h"
|
||||
|
||||
#ifndef MAX_MTEX
|
||||
#define MAX_MTEX 10
|
||||
#define MAX_MTEX 18
|
||||
#endif
|
||||
|
||||
struct MTex;
|
||||
@@ -58,7 +58,7 @@ typedef struct Brush {
|
||||
float alpha; /* opacity */
|
||||
|
||||
short texact, pad;
|
||||
struct MTex *mtex[10];
|
||||
struct MTex *mtex[18]; /* MAX_MTEX */
|
||||
|
||||
struct BrushClone clone;
|
||||
} Brush;
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef struct Group {
|
||||
* the objects that show in the group can change depending
|
||||
* on the last used scene */
|
||||
unsigned int layer;
|
||||
int pad;
|
||||
float dupli_ofs[3];
|
||||
} Group;
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ struct PackedFile;
|
||||
struct anim;
|
||||
struct ImBuf;
|
||||
struct RenderResult;
|
||||
struct GPUTexture;
|
||||
|
||||
|
||||
/* ImageUser is in Texture, in Nodes, Background Image, Image Window, .... */
|
||||
@@ -62,7 +63,8 @@ typedef struct Image {
|
||||
|
||||
char name[240]; /* file path */
|
||||
|
||||
ListBase ibufs; /* not written in file */
|
||||
ListBase ibufs; /* not written in file */
|
||||
struct GPUTexture *gputexture; /* not written in file */
|
||||
|
||||
/* sources from: */
|
||||
struct anim *anim;
|
||||
|
||||
@@ -142,16 +142,24 @@ typedef short IPO_Channel;
|
||||
#define MA_FRESTRAI 25
|
||||
#define MA_ADD 26
|
||||
|
||||
#define MA_MAP1 0x20
|
||||
#define MA_MAP2 0x40
|
||||
#define MA_MAP3 0x80
|
||||
#define MA_MAP4 0x100
|
||||
#define MA_MAP5 0x200
|
||||
#define MA_MAP6 0x400
|
||||
#define MA_MAP7 0x800
|
||||
#define MA_MAP8 0x1000
|
||||
#define MA_MAP9 0x2000
|
||||
#define MA_MAP10 0x4000
|
||||
#define MA_MAP1 1<<5
|
||||
#define MA_MAP2 1<<6
|
||||
#define MA_MAP3 1<<7
|
||||
#define MA_MAP4 1<<8
|
||||
#define MA_MAP5 1<<9
|
||||
#define MA_MAP6 1<<10
|
||||
#define MA_MAP7 1<<11
|
||||
#define MA_MAP8 1<<12
|
||||
#define MA_MAP9 1<<13
|
||||
#define MA_MAP10 1<<14
|
||||
#define MA_MAP11 1<<15
|
||||
#define MA_MAP12 1<<16
|
||||
#define MA_MAP13 1<<17
|
||||
#define MA_MAP14 1<<18
|
||||
#define MA_MAP15 1<<19
|
||||
#define MA_MAP16 1<<20
|
||||
#define MA_MAP17 1<<21
|
||||
#define MA_MAP18 1<<22
|
||||
|
||||
#define TEX_TOTNAM 14
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "DNA_scriptlink_types.h"
|
||||
|
||||
#ifndef MAX_MTEX
|
||||
#define MAX_MTEX 10
|
||||
#define MAX_MTEX 18
|
||||
#endif
|
||||
|
||||
struct MTex;
|
||||
@@ -45,7 +45,8 @@ struct CurveMapping;
|
||||
typedef struct Lamp {
|
||||
ID id;
|
||||
|
||||
short type, mode;
|
||||
short type, pad3;
|
||||
int mode;
|
||||
|
||||
short colormodel, totex;
|
||||
float r, g, b, k;
|
||||
@@ -55,10 +56,9 @@ typedef struct Lamp {
|
||||
|
||||
|
||||
float att1, att2; /* Quad1 and Quad2 attenuation */
|
||||
int pad2;
|
||||
struct CurveMapping *curfalloff;
|
||||
short falloff_type;
|
||||
short pad3;
|
||||
short pad2;
|
||||
|
||||
float clipsta, clipend, shadspotsize;
|
||||
float bias, soft;
|
||||
@@ -99,7 +99,7 @@ typedef struct Lamp {
|
||||
float YF_glowint, YF_glowofs;
|
||||
short YF_glowtype, YF_pad2;
|
||||
|
||||
struct MTex *mtex[10];
|
||||
struct MTex *mtex[18]; /* MAX_MTEX */
|
||||
struct Ipo *ipo;
|
||||
|
||||
/* preview */
|
||||
@@ -137,6 +137,12 @@ typedef struct Lamp {
|
||||
/* yafray: lamp shadowbuffer flag, softlight */
|
||||
/* Since it is used with LOCAL lamp, can't use LA_SHAD */
|
||||
#define LA_YF_SOFT 16384
|
||||
#define LA_LAYER_SHADOW 32768
|
||||
|
||||
/* layer_shadow */
|
||||
#define LA_LAYER_SHADOW_BOTH 0
|
||||
#define LA_LAYER_SHADOW_CAST 1
|
||||
#define LA_LAYER_SHADOW_RECEIVE 2
|
||||
|
||||
/* sun effect type*/
|
||||
#define LA_SUN_EFFECT_SKY 1
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
#ifndef MAX_MTEX
|
||||
#define MAX_MTEX 10
|
||||
#define MAX_MTEX 18
|
||||
#endif
|
||||
|
||||
struct MTex;
|
||||
@@ -88,11 +88,11 @@ typedef struct Material {
|
||||
float sbias; /* shadow bias to prevent terminator prob */
|
||||
float lbias; /* factor to multiply lampbias with (0.0 = no mult) */
|
||||
float shad_alpha; /* in use for irregular shadowbuffer */
|
||||
float padf; /* free padding, take me! */
|
||||
int septex;
|
||||
|
||||
/* for buttons and render*/
|
||||
char rgbsel, texact, pr_type, use_nodes;
|
||||
short pr_back, pr_lamp, septex, ml_flag; /* ml_flag is for disable base material */
|
||||
short pr_back, pr_lamp, pad4, ml_flag; /* ml_flag is for disable base material */
|
||||
|
||||
/* shaders */
|
||||
short diff_shader, spec_shader;
|
||||
@@ -110,7 +110,7 @@ typedef struct Material {
|
||||
short ramp_show, pad3;
|
||||
float rampfac_col, rampfac_spec;
|
||||
|
||||
struct MTex *mtex[10];
|
||||
struct MTex *mtex[18]; /* MAX_MTEX */
|
||||
struct bNodeTree *nodetree;
|
||||
struct Ipo *ipo;
|
||||
struct Group *group; /* light group */
|
||||
@@ -133,6 +133,8 @@ typedef struct Material {
|
||||
int YF_dsmp, YF_preset, YF_djit;
|
||||
|
||||
ScriptLink scriptlink;
|
||||
|
||||
ListBase gpumaterial; /* runtime */
|
||||
} Material;
|
||||
|
||||
/* **************** MATERIAL ********************* */
|
||||
@@ -203,6 +205,7 @@ typedef struct Material {
|
||||
|
||||
/* shade_flag */
|
||||
#define MA_CUBIC 1
|
||||
#define MA_OBCOLOR 2
|
||||
|
||||
/* diff_shader */
|
||||
#define MA_DIFF_LAMBERT 0
|
||||
|
||||
@@ -223,6 +223,8 @@ typedef struct Object {
|
||||
/*#ifdef WITH_VERSE*/
|
||||
void *vnode; /* pointer at object VerseNode */
|
||||
/*#endif*/
|
||||
|
||||
ListBase gpulamp; /* runtime, for lamps only */
|
||||
} Object;
|
||||
|
||||
/* Warning, this is not used anymore because hooks are now modifiers */
|
||||
|
||||
@@ -464,7 +464,7 @@ typedef struct SculptData
|
||||
struct SculptSession *session;
|
||||
|
||||
/* Pointers to all of sculptmodes's textures */
|
||||
struct MTex *mtex[10];
|
||||
struct MTex *mtex[18];
|
||||
|
||||
/* Editable brush shape */
|
||||
struct CurveMapping *cumap;
|
||||
|
||||
@@ -218,6 +218,7 @@ typedef struct bJoystickSensor {
|
||||
#define SENS_NEW 4
|
||||
#define SENS_NOT 8
|
||||
#define SENS_VISIBLE 16
|
||||
#define SENS_PIN 32
|
||||
|
||||
/* sensor->pulse */
|
||||
#define SENS_PULSE_CONT 0
|
||||
|
||||
@@ -367,6 +367,7 @@ typedef struct TexMapping {
|
||||
#define MTEX_BLEND_SAT 11
|
||||
#define MTEX_BLEND_VAL 12
|
||||
#define MTEX_BLEND_COLOR 13
|
||||
#define MTEX_NUM_BLENDTYPES 14
|
||||
|
||||
/* **************** EnvMap ********************* */
|
||||
|
||||
|
||||
@@ -188,6 +188,7 @@ typedef struct UserDef {
|
||||
char fontname[256]; // FILE_MAXDIR+FILE length
|
||||
struct ListBase themes;
|
||||
short undosteps;
|
||||
short undomemory, pad[3];
|
||||
short curssize;
|
||||
short tb_leftmouse, tb_rightmouse;
|
||||
struct SolidLight light[3];
|
||||
|
||||
@@ -38,7 +38,7 @@ struct Ipo;
|
||||
struct MTex;
|
||||
|
||||
#ifndef MAX_MTEX
|
||||
#define MAX_MTEX 10
|
||||
#define MAX_MTEX 18
|
||||
#endif
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ typedef struct World {
|
||||
|
||||
|
||||
struct Ipo *ipo;
|
||||
struct MTex *mtex[10];
|
||||
struct MTex *mtex[18]; /* MAX_MTEX */
|
||||
|
||||
/* previews */
|
||||
struct PreviewImage *preview;
|
||||
|
||||
@@ -30,7 +30,7 @@ SET(INC
|
||||
../python ../render/extern/include ../../../intern/decimation/extern
|
||||
../imbuf ../avi ../../../intern/elbeem/extern
|
||||
../../../intern/iksolver/extern ../blenloader ../quicktime
|
||||
../blenkernel
|
||||
../blenkernel ../../../extern/glew/include ../gpu
|
||||
${SDL_INC}
|
||||
${ZLIB_INC}
|
||||
${PYTHON_INC}
|
||||
|
||||
@@ -11,6 +11,7 @@ incs += ' ../python ../render/extern/include '
|
||||
incs += ' ../imbuf ../avi '
|
||||
incs += ' ../blenloader ../quicktime'
|
||||
incs += ' ../blenkernel ../renderconverter '
|
||||
incs += ' ../gpu #/extern/glew/include '
|
||||
|
||||
|
||||
incs += ' ' + env['BF_PYTHON_INC']
|
||||
|
||||
@@ -42,4 +42,5 @@ CPPFLAGS += -I../../../blenlib
|
||||
CPPFLAGS += -I../../../include
|
||||
CPPFLAGS += -I../../../imbuf
|
||||
CPPFLAGS += -I../../../render/extern/include
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += -I$(OPENGL_HEADERS)
|
||||
|
||||
@@ -42,4 +42,6 @@ CPPFLAGS += -I../../blenlib
|
||||
CPPFLAGS += -I../../include
|
||||
CPPFLAGS += -I../../imbuf
|
||||
CPPFLAGS += -I../../render/extern/include
|
||||
CPPFLAGS += -I../../gpu
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += -I$(OPENGL_HEADERS)
|
||||
|
||||
@@ -44,4 +44,6 @@ CPPFLAGS += -I../../../blenlib
|
||||
CPPFLAGS += -I../../../include
|
||||
CPPFLAGS += -I../../../imbuf
|
||||
CPPFLAGS += -I../../../render/extern/include
|
||||
CPPFLAGS += -I../../../gpu
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += -I$(OPENGL_HEADERS)
|
||||
|
||||
@@ -46,8 +46,13 @@ static void node_shader_exec_camera(void *data, bNode *node, bNodeStack **in, bN
|
||||
VECCOPY(out[0]->vec, shi->co); /* get view vector */
|
||||
out[1]->vec[0]= fabs(shi->co[2]); /* get view z-depth */
|
||||
out[2]->vec[0]= Normalize(out[0]->vec); /* get view distance */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int gpu_shader_camera(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
return GPU_stack_link(mat, "camera", in, out, GPU_builtin(GPU_VIEW_POSITION));
|
||||
}
|
||||
|
||||
bNodeType sh_node_camera= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
@@ -63,6 +68,7 @@ bNodeType sh_node_camera= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_camera
|
||||
};
|
||||
|
||||
|
||||
@@ -56,6 +56,15 @@ static void node_shader_init_curve_vec(bNode* node)
|
||||
node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
float *array;
|
||||
int size;
|
||||
|
||||
curvemapping_table_RGBA(node->storage, &array, &size);
|
||||
return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array));
|
||||
}
|
||||
|
||||
bNodeType sh_node_curve_vec= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_CURVE_VEC,
|
||||
@@ -70,7 +79,8 @@ bNodeType sh_node_curve_vec= {
|
||||
/* initfunc */ node_shader_init_curve_vec,
|
||||
/* freestoragefunc */ node_free_curves,
|
||||
/* copystoragefunc */ node_copy_curves,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_curve_vec
|
||||
|
||||
};
|
||||
|
||||
@@ -100,6 +110,15 @@ static void node_shader_init_curve_rgb(bNode *node)
|
||||
node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
float *array;
|
||||
int size;
|
||||
|
||||
curvemapping_table_RGBA(node->storage, &array, &size);
|
||||
return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array));
|
||||
}
|
||||
|
||||
bNodeType sh_node_curve_rgb= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_CURVE_RGB,
|
||||
@@ -114,6 +133,7 @@ bNodeType sh_node_curve_rgb= {
|
||||
/* initfunc */ node_shader_init_curve_rgb,
|
||||
/* freestoragefunc */ node_free_curves,
|
||||
/* copystoragefunc */ node_copy_curves,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_curve_rgb
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "../SHD_util.h"
|
||||
|
||||
#include "DNA_customdata_types.h"
|
||||
|
||||
/* **************** GEOMETRY ******************** */
|
||||
|
||||
@@ -124,6 +125,18 @@ static void node_shader_init_geometry(bNode *node)
|
||||
node->storage= MEM_callocN(sizeof(NodeGeometry), "NodeGeometry");
|
||||
}
|
||||
|
||||
static int gpu_shader_geom(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
NodeGeometry *ngeo= (NodeGeometry*)node->storage;
|
||||
GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
|
||||
GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname);
|
||||
GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname);
|
||||
|
||||
return GPU_stack_link(mat, "geom", in, out,
|
||||
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
|
||||
GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol);
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
bNodeType sh_node_geom= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
@@ -139,6 +152,7 @@ bNodeType sh_node_geom= {
|
||||
/* initfunc */ node_shader_init_geometry,
|
||||
/* freestoragefunc */ node_free_standard_storage,
|
||||
/* copystoragefunc */ node_copy_standard_storage,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_geom
|
||||
|
||||
};
|
||||
|
||||
@@ -71,6 +71,12 @@ static void node_shader_exec_hue_sat(void *data, bNode *node, bNodeStack **in, b
|
||||
do_hue_sat_fac(node, out[0]->vec, in[0]->vec, in[1]->vec, in[2]->vec, in[4]->vec, in[3]->vec);
|
||||
}
|
||||
|
||||
|
||||
static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
return GPU_stack_link(mat, "hue_sat", in, out);
|
||||
}
|
||||
|
||||
bNodeType sh_node_hue_sat= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_HUE_SAT,
|
||||
@@ -85,7 +91,8 @@ bNodeType sh_node_hue_sat= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_hue_sat
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -64,6 +64,11 @@ bNodeStack **out)
|
||||
VECCOPY(out[0]->vec, col);
|
||||
}
|
||||
|
||||
static int gpu_shader_invert(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
return GPU_stack_link(mat, "invert", in, out);
|
||||
}
|
||||
|
||||
bNodeType sh_node_invert= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_INVERT,
|
||||
@@ -78,6 +83,7 @@ bNodeType sh_node_invert= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_invert
|
||||
};
|
||||
|
||||
|
||||
@@ -69,6 +69,20 @@ static void node_shader_init_mapping(bNode *node)
|
||||
node->storage= add_mapping();
|
||||
}
|
||||
|
||||
static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
TexMapping *texmap= node->storage;
|
||||
float domin= (texmap->flag & TEXMAP_CLIP_MIN) != 0;
|
||||
float domax= (texmap->flag & TEXMAP_CLIP_MAX) != 0;
|
||||
GPUNodeLink *tmat = GPU_uniform((float*)texmap->mat);
|
||||
GPUNodeLink *tmin = GPU_uniform(texmap->min);
|
||||
GPUNodeLink *tmax = GPU_uniform(texmap->max);
|
||||
GPUNodeLink *tdomin = GPU_uniform(&domin);
|
||||
GPUNodeLink *tdomax = GPU_uniform(&domax);
|
||||
|
||||
return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
|
||||
}
|
||||
|
||||
bNodeType sh_node_mapping= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_MAPPING,
|
||||
@@ -83,7 +97,8 @@ bNodeType sh_node_mapping= {
|
||||
/* initfunc */ node_shader_init_mapping,
|
||||
/* freestoragefunc */ node_free_standard_storage,
|
||||
/* copystoragefunc */ node_copy_standard_storage,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_mapping
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -182,6 +182,77 @@ static void node_shader_init_material(bNode* node)
|
||||
node->custom1= SH_NODE_MAT_DIFF|SH_NODE_MAT_SPEC;
|
||||
}
|
||||
|
||||
static int gpu_shader_material(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
if(node->id) {
|
||||
GPUShadeInput shi;
|
||||
GPUShadeResult shr;
|
||||
|
||||
GPU_shadeinput_set(mat, (Material*)node->id, &shi);
|
||||
|
||||
/* write values */
|
||||
if(in[MAT_IN_COLOR].hasinput)
|
||||
shi.rgb = in[MAT_IN_COLOR].link;
|
||||
|
||||
if(in[MAT_IN_SPEC].hasinput)
|
||||
shi.specrgb = in[MAT_IN_SPEC].link;
|
||||
|
||||
if(in[MAT_IN_REFL].hasinput)
|
||||
shi.refl = in[MAT_IN_REFL].link;
|
||||
|
||||
/* retrieve normal */
|
||||
if(in[MAT_IN_NORMAL].hasinput) {
|
||||
GPUNodeLink *tmp;
|
||||
shi.vn = in[MAT_IN_NORMAL].link;
|
||||
GPU_link(mat, "vec_math_normalize", shi.vn, &shi.vn, &tmp);
|
||||
}
|
||||
|
||||
/* custom option to flip normal */
|
||||
if(node->custom1 & SH_NODE_MAT_NEG)
|
||||
GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn);
|
||||
|
||||
if (node->type == SH_NODE_MATERIAL_EXT) {
|
||||
if(in[MAT_IN_AMB].hasinput)
|
||||
shi.amb= in[MAT_IN_AMB].link;
|
||||
if(in[MAT_IN_EMIT].hasinput)
|
||||
shi.emit= in[MAT_IN_EMIT].link;
|
||||
if(in[MAT_IN_ALPHA].hasinput)
|
||||
shi.alpha= in[MAT_IN_ALPHA].link;
|
||||
}
|
||||
|
||||
GPU_shaderesult_set(&shi, &shr); /* clears shr */
|
||||
|
||||
/* write to outputs */
|
||||
if(node->custom1 & SH_NODE_MAT_DIFF) {
|
||||
if(node->custom1 & SH_NODE_MAT_SPEC)
|
||||
out[MAT_OUT_COLOR].link= shr.combined;
|
||||
else
|
||||
out[MAT_OUT_COLOR].link= shr.diff;
|
||||
}
|
||||
else if(node->custom1 & SH_NODE_MAT_SPEC) {
|
||||
out[MAT_OUT_COLOR].link= shr.spec;
|
||||
}
|
||||
else
|
||||
GPU_link(mat, "set_rgb_zero", &out[MAT_OUT_COLOR].link);
|
||||
|
||||
GPU_link(mat, "mtex_alpha_to_col", out[MAT_OUT_COLOR].link, shr.alpha, &out[MAT_OUT_COLOR].link);
|
||||
|
||||
out[MAT_OUT_ALPHA].link = shr.alpha; //
|
||||
|
||||
if(node->custom1 & SH_NODE_MAT_NEG)
|
||||
GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn);
|
||||
out[MAT_OUT_NORMAL].link = shi.vn;
|
||||
|
||||
if (node->type == SH_NODE_MATERIAL_EXT) {
|
||||
out[MAT_OUT_DIFFUSE].link = shr.diff;
|
||||
out[MAT_OUT_SPEC].link = shr.spec;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bNodeType sh_node_material= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
@@ -197,8 +268,8 @@ bNodeType sh_node_material= {
|
||||
/* initfunc */ node_shader_init_material,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_material
|
||||
};
|
||||
|
||||
bNodeType sh_node_material_ext= {
|
||||
@@ -215,7 +286,7 @@ bNodeType sh_node_material_ext= {
|
||||
/* initfunc */ node_shader_init_material,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_material
|
||||
};
|
||||
|
||||
|
||||
@@ -194,6 +194,46 @@ bNodeStack **out)
|
||||
}
|
||||
}
|
||||
|
||||
static int gpu_shader_math(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
static char *names[] = {"math_add", "math_subtract", "math_multiply",
|
||||
"math_divide", "math_sine", "math_cosine", "math_tangnet", "math_asin",
|
||||
"math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max",
|
||||
"math_round", "math_less_than", "math_greater_than"};
|
||||
|
||||
switch (node->custom1) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 15:
|
||||
case 16:
|
||||
GPU_stack_link(mat, names[node->custom1], NULL, out,
|
||||
GPU_socket(&in[0]), GPU_socket(&in[1]));
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 14:
|
||||
if(in[0].hasinput || !in[1].hasinput)
|
||||
GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[0]));
|
||||
else
|
||||
GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[1]));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bNodeType sh_node_math= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_MATH,
|
||||
@@ -208,6 +248,7 @@ bNodeType sh_node_math= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_math
|
||||
};
|
||||
|
||||
|
||||
@@ -60,6 +60,17 @@ static void node_shader_exec_mix_rgb(void *data, bNode *node, bNodeStack **in, b
|
||||
VECCOPY(out[0]->vec, col);
|
||||
}
|
||||
|
||||
static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
static char *names[] = {"mix_blend", "mix_add", "mix_mult", "mix_sub",
|
||||
"mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light",
|
||||
"mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat",
|
||||
"mix_val", "mix_color"};
|
||||
|
||||
return GPU_stack_link(mat, names[node->custom1], in, out);
|
||||
}
|
||||
|
||||
|
||||
bNodeType sh_node_mix_rgb= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_MIX_RGB,
|
||||
@@ -74,6 +85,7 @@ bNodeType sh_node_mix_rgb= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_mix_rgb
|
||||
|
||||
};
|
||||
|
||||
@@ -57,6 +57,14 @@ static void node_shader_exec_normal(void *data, bNode *node, bNodeStack **in, bN
|
||||
out[1]->vec[0]= -INPR(out[0]->vec, vec);
|
||||
}
|
||||
|
||||
static int gpu_shader_normal(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
bNodeSocket *sock= node->outputs.first;
|
||||
GPUNodeLink *vec = GPU_uniform(sock->ns.vec);
|
||||
|
||||
return GPU_stack_link(mat, "normal", in, out, vec);
|
||||
}
|
||||
|
||||
bNodeType sh_node_normal= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_NORMAL,
|
||||
@@ -71,6 +79,7 @@ bNodeType sh_node_normal= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_normal
|
||||
};
|
||||
|
||||
|
||||
@@ -62,6 +62,19 @@ static void node_shader_exec_output(void *data, bNode *node, bNodeStack **in, bN
|
||||
}
|
||||
}
|
||||
|
||||
static int gpu_shader_output(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
GPUNodeLink *outlink;
|
||||
|
||||
/*if(in[1].hasinput)
|
||||
GPU_material_enable_alpha(mat);*/
|
||||
|
||||
GPU_stack_link(mat, "output_node", in, out, &outlink);
|
||||
GPU_material_output_link(mat, outlink);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bNodeType sh_node_output= {
|
||||
/* *next,*prev */ NULL, NULL,
|
||||
/* type code */ SH_NODE_OUTPUT,
|
||||
@@ -76,7 +89,8 @@ bNodeType sh_node_output= {
|
||||
/* initfunc */ NULL,
|
||||
/* freestoragefunc */ NULL,
|
||||
/* copystoragefunc */ NULL,
|
||||
/* id */ NULL
|
||||
/* id */ NULL, NULL, NULL,
|
||||
/* gpufunc */ gpu_shader_output
|
||||
|
||||
};
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user