diff options
Diffstat (limited to 'source')
218 files changed, 16353 insertions, 1725 deletions
diff --git a/source/blender/blenfont/CMakeLists.txt b/source/blender/blenfont/CMakeLists.txt index 2debe516dd7..346d5bc64b8 100644 --- a/source/blender/blenfont/CMakeLists.txt +++ b/source/blender/blenfont/CMakeLists.txt @@ -26,11 +26,13 @@ set(INC ../blenkernel ../blenlib ../editors/include + ../gpu ../makesdna ../makesrna ../python ../imbuf ../../../intern/guardedalloc + ../../../intern/glew-mx ../../../intern/locale ) @@ -58,7 +60,7 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) blender_add_lib(bf_blenfont "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index cdccbe044bb..3944255c0ad 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -514,7 +514,6 @@ static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param) glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* Save the current matrix mode. */ glGetIntegerv(GL_MATRIX_MODE, mode); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 0caf7d11c55..bd03dc71a92 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -38,6 +38,7 @@ set(INC ../nodes ../render/extern/include ../../../intern/guardedalloc + ../../../intern/glew-mx ../../../intern/iksolver/extern ../../../intern/memutil ../../../intern/mikktspace @@ -272,7 +273,7 @@ set(SRC intern/pbvh_intern.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_AUDASPACE) list(APPEND INC diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index cc849570f28..52ded77b117 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -72,11 +72,10 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm); #include "BLI_sys_types.h" /* for intptr_t support */ -#include "GL/glew.h" - #include "GPU_buffers.h" #include "GPU_draw.h" #include "GPU_extensions.h" +#include "GPU_glew.h" #include "GPU_material.h" /* very slow! enable for testing only! */ diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 116f9d9e64c..08052127fbf 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -34,8 +34,6 @@ * \ingroup bke */ -#include "GL/glew.h" - #include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_edgehash.h" @@ -62,6 +60,7 @@ #include "GPU_buffers.h" #include "GPU_draw.h" #include "GPU_extensions.h" +#include "GPU_glew.h" #include "GPU_material.h" #include <string.h> diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 40a4bc22ce9..ce7804d9878 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -41,8 +41,6 @@ * is likely to be a little slow. */ -#include "GL/glew.h" - #include "BLI_math.h" #include "BLI_jitter.h" #include "BLI_bitmap.h" @@ -58,6 +56,7 @@ #include "MEM_guardedalloc.h" #include "GPU_extensions.h" +#include "GPU_glew.h" extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */ diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index ccedb6f6b71..3e763016efb 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -1644,7 +1644,7 @@ void BKE_pbvh_raycast_project_ray_root (PBVH *bvh, bool original, float ray_star } -//#include <GL/glew.h> +//#include "GPU_glew.h" typedef struct { DMSetMaterial setMaterial; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 89245d2300d..90ac712e55a 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -33,8 +33,6 @@ /* Part of the code copied from elbeem fluid library, copyright by Nils Thuerey */ -#include <GL/glew.h> - #include "MEM_guardedalloc.h" #include <float.h> @@ -84,6 +82,8 @@ #include "RE_shader_ext.h" +#include "GPU_glew.h" + /* UNUSED so far, may be enabled later */ /* #define USE_SMOKE_COLLISION_DM */ diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 2e96eecebcf..0bd9517dcfd 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -72,10 +72,9 @@ # include "BLI_array.h" #endif -#include "GL/glew.h" - #include "GPU_draw.h" #include "GPU_extensions.h" +#include "GPU_glew.h" #include "GPU_material.h" #include "CCGSubSurf.h" diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 0eac92c1db9..5868912e762 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -72,6 +72,16 @@ void mul_m4_m4m3(float R[4][4], float A[4][4], float B[3][3]); void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]); void mul_m3_m3m4(float R[3][3], float A[4][4], float B[3][3]); + +void mul_m4_m4m4_q(float m1[4][4], float m3[4][4], float m2[4][4]); +void mul_m4_m3m4_q(float m1[4][4], float m3[4][4], float m2[3][3]); + +void mul_serie_m3(float R[3][3], + float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], + float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]); +void mul_serie_m4(float R[4][4], + float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], + float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]); /* mul_m3_series */ void _va_mul_m3_series_3(float R[3][3], float M1[3][3], float M2[3][3]) ATTR_NONNULL(); void _va_mul_m3_series_4(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3]) ATTR_NONNULL(); @@ -105,6 +115,8 @@ void mul_v3_m4v3(float r[3], float M[4][4], const float v[3]); void mul_v2_m4v3(float r[2], float M[4][4], const float v[3]); void mul_v2_m2v2(float r[2], float M[2][2], const float v[2]); void mul_m2v2(float M[2][2], float v[2]); +void mul_v4_m4v3(float r[4], float M[4][4], const float v[3]); +void mul_v3_m4v3_q(float r[3], float M[4][4], const float v[3]); void mul_mat3_m4_v3(float M[4][4], float r[3]); void mul_m4_v4(float M[4][4], float r[4]); void mul_v4_m4v4(float r[4], float M[4][4], const float v[4]); @@ -190,6 +202,8 @@ void invert_m4_m4_safe(float Ainv[4][4], float A[4][4]); void scale_m3_fl(float R[3][3], float scale); void scale_m4_fl(float R[4][4], float scale); +void scale_m4(float m[][4], float x, float y, float z); + float mat3_to_scale(float M[3][3]); float mat4_to_scale(float M[4][4]); @@ -201,6 +215,7 @@ void mat4_to_size(float r[3], float M[4][4]); void translate_m4(float mat[4][4], float tx, float ty, float tz); void rotate_m4(float mat[4][4], const char axis, const float angle); +void rotate_m4_right(float mat[4][4], const char axis); void rotate_m2(float mat[2][2], const float angle); void transform_pivot_set_m4(float mat[4][4], const float pivot[3]); @@ -227,6 +242,13 @@ bool is_negative_m4(float mat[4][4]); bool is_zero_m3(float mat[3][3]); bool is_zero_m4(float mat[4][4]); +/******************************** Projections ********************************/ + +void mat4_ortho_set(float m[4][4], float left, float right, float bottom, float top, float nearVal, float farVal); +void mat4_frustum_set(float m[4][4], float left, float right, float bottom, float top, float nearVal, float farVal); + +void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3]); + /* SpaceTransform helper */ typedef struct SpaceTransform { float local2target[4][4]; @@ -243,6 +265,7 @@ void BLI_space_transform_invert_normal(const struct SpaceTransform *data, float #define BLI_SPACE_TRANSFORM_SETUP(data, local, target) \ BLI_space_transform_from_matrices((data), (local)->obmat, (target)->obmat) + /*********************************** Other ***********************************/ void print_m3(const char *str, float M[3][3]); diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 6885a5aa351..34e65e61981 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -266,7 +266,7 @@ void project_v3_plane(float v[3], const float n[3], const float p[3]); void reflect_v3_v3v3(float r[3], const float v[3], const float n[3]); void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3]); void ortho_v3_v3(float p[3], const float v[3]); -void ortho_v2_v2(float p[2], const float v[2]); +void ortho_v2_v2(float p[3], const float v[3]); void bisect_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]); void rotate_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle); void rotate_normalized_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 683b3c4c438..63a6b2a1943 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -297,14 +297,36 @@ (v1)[2] = FTOCHAR((v2[2])); \ (v1)[3] = FTOCHAR((v2[3])); \ } (void)0 -#define VECCOPY(v1, v2) { \ +#define VEC2D(v1, x, y) { \ + *((v1) + 0) = x; \ + *((v1) + 1) = y; \ +} (void)0 +#define VEC3D(v1, x, y, z) { \ + *((v1) + 0) = x; \ + *((v1) + 1) = y; \ + *((v1) + 2) = z; \ +} (void)0 +#define VEC4D(v1, x, y, z, w) { \ + *((v1) + 0) = x; \ + *((v1) + 1) = y; \ + *((v1) + 2) = z; \ + *((v1) + 3) = w; \ +} (void)0 +#define VECCOPY2D(v1, v2) { \ *(v1) = *(v2); \ *(v1 + 1) = *(v2 + 1); \ - *(v1 + 2) = *(v2 + 2); \ } (void)0 -#define VECCOPY2D(v1, v2) { \ +#define VECCOPY3D(v1, v2) { \ *(v1) = *(v2); \ *(v1 + 1) = *(v2 + 1); \ + *(v1 + 2) = *(v2 + 2); \ +} (void)0 +#define VECCOPY(v1, v2) VECCOPY3D(v1, v2) +#define VECCOPY4D(v1, v2) { \ + *(v1 + 0) = *(v2 + 0); \ + *(v1 + 1) = *(v2 + 1); \ + *(v1 + 2) = *(v2 + 2); \ + *(v1 + 3) = *(v2 + 3); \ } (void)0 #define VECADD(v1, v2, v3) { \ *(v1) = *(v2) + *(v3); \ diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 888587e055c..228bb1008b1 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -186,26 +186,7 @@ void mul_m4_m4m4(float m1[4][4], float m3_[4][4], float m2_[4][4]) copy_m4_m4(m3, m3_); /* matrix product: m1[j][k] = m2[j][i].m3[i][k] */ - m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0] + m2[0][3] * m3[3][0]; - m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1] + m2[0][3] * m3[3][1]; - m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * m3[2][2] + m2[0][3] * m3[3][2]; - m1[0][3] = m2[0][0] * m3[0][3] + m2[0][1] * m3[1][3] + m2[0][2] * m3[2][3] + m2[0][3] * m3[3][3]; - - m1[1][0] = m2[1][0] * m3[0][0] + m2[1][1] * m3[1][0] + m2[1][2] * m3[2][0] + m2[1][3] * m3[3][0]; - m1[1][1] = m2[1][0] * m3[0][1] + m2[1][1] * m3[1][1] + m2[1][2] * m3[2][1] + m2[1][3] * m3[3][1]; - m1[1][2] = m2[1][0] * m3[0][2] + m2[1][1] * m3[1][2] + m2[1][2] * m3[2][2] + m2[1][3] * m3[3][2]; - m1[1][3] = m2[1][0] * m3[0][3] + m2[1][1] * m3[1][3] + m2[1][2] * m3[2][3] + m2[1][3] * m3[3][3]; - - m1[2][0] = m2[2][0] * m3[0][0] + m2[2][1] * m3[1][0] + m2[2][2] * m3[2][0] + m2[2][3] * m3[3][0]; - m1[2][1] = m2[2][0] * m3[0][1] + m2[2][1] * m3[1][1] + m2[2][2] * m3[2][1] + m2[2][3] * m3[3][1]; - m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2] + m2[2][3] * m3[3][2]; - m1[2][3] = m2[2][0] * m3[0][3] + m2[2][1] * m3[1][3] + m2[2][2] * m3[2][3] + m2[2][3] * m3[3][3]; - - m1[3][0] = m2[3][0] * m3[0][0] + m2[3][1] * m3[1][0] + m2[3][2] * m3[2][0] + m2[3][3] * m3[3][0]; - m1[3][1] = m2[3][0] * m3[0][1] + m2[3][1] * m3[1][1] + m2[3][2] * m3[2][1] + m2[3][3] * m3[3][1]; - m1[3][2] = m2[3][0] * m3[0][2] + m2[3][1] * m3[1][2] + m2[3][2] * m3[2][2] + m2[3][3] * m3[3][2]; - m1[3][3] = m2[3][0] * m3[0][3] + m2[3][1] * m3[1][3] + m2[3][2] * m3[2][3] + m2[3][3] * m3[3][3]; - + mul_m4_m4m4_q(m1, m3, m2); } void mul_m3_m3m3(float m1[3][3], float m3_[3][3], float m2_[3][3]) @@ -291,6 +272,88 @@ void mul_m4_m3m4(float m1[4][4], float m3_[3][3], float m2_[4][4]) m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2]; } +void mul_m4_m4m4_q(float m1[4][4], float m3[4][4], float m2[4][4]) +{ + /* matrix product: m1[j][k] = m2[j][i].m3[i][k] */ + m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0] + m2[0][3] * m3[3][0]; + m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1] + m2[0][3] * m3[3][1]; + m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * m3[2][2] + m2[0][3] * m3[3][2]; + m1[0][3] = m2[0][0] * m3[0][3] + m2[0][1] * m3[1][3] + m2[0][2] * m3[2][3] + m2[0][3] * m3[3][3]; + + m1[1][0] = m2[1][0] * m3[0][0] + m2[1][1] * m3[1][0] + m2[1][2] * m3[2][0] + m2[1][3] * m3[3][0]; + m1[1][1] = m2[1][0] * m3[0][1] + m2[1][1] * m3[1][1] + m2[1][2] * m3[2][1] + m2[1][3] * m3[3][1]; + m1[1][2] = m2[1][0] * m3[0][2] + m2[1][1] * m3[1][2] + m2[1][2] * m3[2][2] + m2[1][3] * m3[3][2]; + m1[1][3] = m2[1][0] * m3[0][3] + m2[1][1] * m3[1][3] + m2[1][2] * m3[2][3] + m2[1][3] * m3[3][3]; + + m1[2][0] = m2[2][0] * m3[0][0] + m2[2][1] * m3[1][0] + m2[2][2] * m3[2][0] + m2[2][3] * m3[3][0]; + m1[2][1] = m2[2][0] * m3[0][1] + m2[2][1] * m3[1][1] + m2[2][2] * m3[2][1] + m2[2][3] * m3[3][1]; + m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2] + m2[2][3] * m3[3][2]; + m1[2][3] = m2[2][0] * m3[0][3] + m2[2][1] * m3[1][3] + m2[2][2] * m3[2][3] + m2[2][3] * m3[3][3]; + + m1[3][0] = m2[3][0] * m3[0][0] + m2[3][1] * m3[1][0] + m2[3][2] * m3[2][0] + m2[3][3] * m3[3][0]; + m1[3][1] = m2[3][0] * m3[0][1] + m2[3][1] * m3[1][1] + m2[3][2] * m3[2][1] + m2[3][3] * m3[3][1]; + m1[3][2] = m2[3][0] * m3[0][2] + m2[3][1] * m3[1][2] + m2[3][2] * m3[2][2] + m2[3][3] * m3[3][2]; + m1[3][3] = m2[3][0] * m3[0][3] + m2[3][1] * m3[1][3] + m2[3][2] * m3[2][3] + m2[3][3] * m3[3][3]; +} + +void mul_m4_m3m4_q(float m1[4][4], float m3[4][4], float m2[3][3]) +{ + /* matrix product: m1[j][k] = m2[j][i].m3[i][k] */ + m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0]; + m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1]; + m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * m3[2][2]; + m1[0][3] = m2[0][0] * m3[0][3] + m2[0][1] * m3[1][3] + m2[0][2] * m3[2][3]; + + m1[1][0] = m2[1][0] * m3[0][0] + m2[1][1] * m3[1][0] + m2[1][2] * m3[2][0]; + m1[1][1] = m2[1][0] * m3[0][1] + m2[1][1] * m3[1][1] + m2[1][2] * m3[2][1]; + m1[1][2] = m2[1][0] * m3[0][2] + m2[1][1] * m3[1][2] + m2[1][2] * m3[2][2]; + m1[1][3] = m2[1][0] * m3[0][3] + m2[1][1] * m3[1][3] + m2[1][2] * m3[2][3]; + + m1[2][0] = m2[2][0] * m3[0][0] + m2[2][1] * m3[1][0] + m2[2][2] * m3[2][0]; + m1[2][1] = m2[2][0] * m3[0][1] + m2[2][1] * m3[1][1] + m2[2][2] * m3[2][1]; + m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2]; + m1[2][3] = m2[2][0] * m3[0][3] + m2[2][1] * m3[1][3] + m2[2][2] * m3[2][3]; + + m1[3][0] = m3[3][0]; + m1[3][1] = m3[3][1]; + m1[3][2] = m3[3][2]; + m1[3][3] = m3[3][3]; +} + + + +void mul_serie_m3(float answ[3][3], + float m1[3][3], float m2[3][3], float m3[3][3], + float m4[3][3], float m5[3][3], float m6[3][3], + float m7[3][3], float m8[3][3]) +{ + float temp[3][3]; + + if (m1 == NULL || m2 == NULL) return; + + mul_m3_m3m3(answ, m2, m1); + if (m3) { + mul_m3_m3m3(temp, m3, answ); + if (m4) { + mul_m3_m3m3(answ, m4, temp); + if (m5) { + mul_m3_m3m3(temp, m5, answ); + if (m6) { + mul_m3_m3m3(answ, m6, temp); + if (m7) { + mul_m3_m3m3(temp, m7, answ); + if (m8) { + mul_m3_m3m3(answ, m8, temp); + } + else copy_m3_m3(answ, temp); + } + } + else copy_m3_m3(answ, temp); + } + } + else copy_m3_m3(answ, temp); + } +} /** \name Macro helpers for: mul_m3_series * \{ */ @@ -493,6 +556,22 @@ void mul_m2v2(float mat[2][2], float vec[2]) mul_v2_m2v2(vec, mat, vec); } +void mul_v4_m4v3(float out[4], float mat[][4], const float vec[3]) +{ + out[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; + out[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; + out[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; + out[3] = vec[0] * mat[0][3] + vec[1] * mat[1][3] + mat[2][3] * vec[2] + mat[3][3]; +} + +void mul_v3_m4v3_q(float out[3], float mat[][4], const float vec[3]) +{ + out[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; + out[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; + out[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; + +} + /* same as mul_m4_v3() but doesnt apply translation component */ void mul_mat3_m4_v3(float mat[4][4], float vec[3]) { @@ -1478,11 +1557,19 @@ void scale_m4_fl(float m[4][4], float scale) m[3][0] = m[3][1] = m[3][2] = 0.0; } +void scale_m4(float m[][4], float x, float y, float z) +{ + m[0][0]*=x; m[0][1]*=x; m[0][2]*=x; m[0][3]*=x; + m[1][0]*=y; m[1][1]*=y; m[1][2]*=y; m[1][3]*=y; + m[2][0]*=z; m[2][1]*=z; m[2][2]*=z; m[2][3]*=z; +} + void translate_m4(float mat[4][4], float Tx, float Ty, float Tz) { mat[3][0] += (Tx * mat[0][0] + Ty * mat[1][0] + Tz * mat[2][0]); mat[3][1] += (Tx * mat[0][1] + Ty * mat[1][1] + Tz * mat[2][1]); mat[3][2] += (Tx * mat[0][2] + Ty * mat[1][2] + Tz * mat[2][2]); + mat[3][3] += (Tx * mat[0][3] + Ty * mat[1][3] + Tz * mat[2][3]); } void rotate_m4(float mat[4][4], const char axis, const float angle) @@ -1554,6 +1641,60 @@ void transform_pivot_set_m4(float mat[4][4], const float pivot[3]) mul_m4_m4m4(mat, mat, tmat); } +void rotate_m4_right(float mat[][4], const char axis) +{ +#define COORD(x,y) (4*x + y) + const static char mrotx[] = {1, 2}; + const static char mrotxn[] = {2, 1}; + + const static char mroty[] = {2, 0}; + const static char mrotyn[] = {0, 2}; + + const static char mrotz[] = {0, 1}; + const static char mrotzn[] = {1, 0}; + +#undef COORD + + const char * rotmat; + float tmpf; + int i; + + + switch(axis) + { + case 'X': + rotmat = mrotx; + break; + case (char)-'X': + rotmat = mrotxn; + break; + case 'Y': + rotmat = mroty; + break; + case (char)-'Y': + rotmat = mrotyn; + break; + case 'Z': + rotmat = mrotz; + break; + case (char)-'Z': + rotmat = mrotzn; + break; + default: + BLI_assert(0); + + } + + for(i=0; i<3; i++) + { + tmpf = mat[rotmat[1]][i]; + mat[rotmat[1]][i] = -1.0f*mat[rotmat[0]][i]; + mat[rotmat[0]][i] = tmpf; + + } + +} + void blend_m3_m3m3(float out[3][3], float dst[3][3], float src[3][3], const float srcweight) { float srot[3][3], drot[3][3]; @@ -2194,6 +2335,41 @@ void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon) mul_m4_series(Ainv, U, Wm, V); } +void mat4_ortho_set(float m[][4], float left, float right, float bottom, float top, float nearVal, float farVal) +{ + m[0][0] = 2/(right-left); m[1][0] = 0; m[2][0] = 0; m[3][0] = -(right+left)/(right-left); + m[0][1] = 0; m[1][1] = 2/(top-bottom); m[2][1] = 0; m[3][1] = -(top+bottom)/(top-bottom); + m[0][2] = 0; m[1][2] = 0; m[2][2] = -2/(farVal-nearVal); m[3][2] = -(farVal+nearVal)/(farVal-nearVal); + m[0][3] = 0; m[1][3] = 0; m[2][3] = 0; m[3][3] = 1; +} + +void mat4_frustum_set(float m[][4], float left, float right, float bottom, float top, float nearVal, float farVal) +{ + m[0][0] = 2*nearVal/(right-left); m[1][0] = 0; m[2][0] = (right+left)/(right-left); m[3][0] = 0; + m[0][1] = 0; m[1][1] = 2*nearVal/(top-bottom); m[2][1] = (top+bottom)/(top-bottom); m[3][1] = 0; + m[0][2] = 0; m[1][2] = 0; m[2][2] = -(farVal+nearVal)/(farVal-nearVal); m[3][2] = -2*farVal*nearVal/(farVal-nearVal); + m[0][3] = 0; m[1][3] = 0; m[2][3] = -1; m[3][3] = 0; +} + +/* Loosly based on Mesa implementation of gluLookAt */ +void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3]) +{ + float side[3]; + + normalize_v3(lookdir); + + cross_v3_v3v3(side, lookdir, camup); + + normalize_v3(side); + + cross_v3_v3v3(camup, side, lookdir); + + m[0][0] = side [0]; m[1][0] = side [1]; m[2][0] = side [2]; m[3][0] = 0; + m[0][1] = camup [0]; m[1][1] = camup [1]; m[2][1] = camup [2]; m[3][1] = 0; + m[0][2] = -lookdir[0]; m[1][2] = -lookdir[1]; m[2][2] = -lookdir[2]; m[3][2] = 0; + m[0][3] = 0; m[1][3] = 0; m[2][3] = 0; m[3][3] = 1; +} + void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon) { /* try regular inverse when possible, otherwise fall back to slow svd */ diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 6b37b0d5d32..c904b963e54 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -669,7 +669,7 @@ void ortho_v3_v3(float p[3], const float v[3]) /** * no brainer compared to v3, just have for consistency. */ -void ortho_v2_v2(float p[2], const float v[2]) +void ortho_v2_v2(float p[3], const float v[3]) { BLI_assert(p != v); diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 5529433f6c9..3ed4a561698 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -97,6 +97,19 @@ MINLINE void copy_v4_fl(float r[4], float f) r[3] = f; } +MINLINE void copy_v2_flfl(float r[2], float f0, float f1) +{ + r[0] = f0; + r[1] = f1; +} + +MINLINE void copy_v3_flflfl(float r[3], float f0, float f1, float f2) +{ + r[0] = f0; + r[1] = f1; + r[2] = f2; +} + /* short */ MINLINE void copy_v2_v2_char(char r[2], const char a[2]) { diff --git a/source/blender/editors/animation/CMakeLists.txt b/source/blender/editors/animation/CMakeLists.txt index d6030a967d5..b9f50a6cdf1 100644 --- a/source/blender/editors/animation/CMakeLists.txt +++ b/source/blender/editors/animation/CMakeLists.txt @@ -23,10 +23,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -57,4 +59,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_animation "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 7d8e278f0cf..c00fe6f103e 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -3382,7 +3382,6 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float selected = 0; /* set blending again, as may not be set in previous step */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* step 1) draw backdrop ........................................... */ diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 9c3f310a417..029c3b66043 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -140,7 +140,6 @@ void ANIM_draw_previewrange(const bContext *C, View2D *v2d, int end_frame_width) /* only draw this if preview range is set */ if (PRVRANGEON) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glColor4f(0.0f, 0.0f, 0.0f, 0.4f); diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 7cd47fab83a..0789aa6c148 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -330,7 +330,6 @@ static void draw_marker(View2D *v2d, TimeMarker *marker, int cfra, int flag) glScalef(1.0f / xscale, 1.0f, 1.0f); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* vertical line - dotted */ #ifdef DURIAN_CAMERA_SWITCH diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt index 9aa17f1e503..d82da1c827f 100644 --- a/source/blender/editors/armature/CMakeLists.txt +++ b/source/blender/editors/armature/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ../../windowmanager ../../gpu ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -74,4 +75,6 @@ if(WITH_OPENNL) ) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_armature "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index ba105325b97..85dcb2ed4da 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -2069,7 +2069,6 @@ static void sk_drawSketch(Scene *scene, View3D *UNUSED(v3d), SK_Sketch *sketch, glPushMatrix(); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); switch (sketch->next_point.mode) { case PT_SNAP: diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt index 904ad4892ed..5dc9679777f 100644 --- a/source/blender/editors/gpencil/CMakeLists.txt +++ b/source/blender/editors/gpencil/CMakeLists.txt @@ -24,10 +24,12 @@ set(INC ../../blenkernel ../../blenlib ../../imbuf + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -50,4 +52,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_gpencil "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 5a838d7bc39..35982c63357 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -556,7 +556,6 @@ static void gp_draw_data(bGPdata *gpd, int offsx, int offsy, int winx, int winy, glEnable(GL_LINE_SMOOTH); /* turn on alpha-blending */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* loop over layers, drawing them */ diff --git a/source/blender/editors/include/BIF_gl.h b/source/blender/editors/include/BIF_gl.h index 9fa603966b6..cd26bb22ada 100644 --- a/source/blender/editors/include/BIF_gl.h +++ b/source/blender/editors/include/BIF_gl.h @@ -33,7 +33,7 @@ #ifndef __BIF_GL_H__ #define __BIF_GL_H__ -#include "GL/glew.h" +#include "GPU_glew.h" #ifdef __APPLE__ diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index e13517adbb3..b921d17104c 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -30,6 +30,7 @@ set(INC ../../python ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -70,4 +71,6 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_interface "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 695c8866d08..c3f63f8a7fe 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1329,9 +1329,6 @@ void uiDrawBlock(const bContext *C, uiBlock *block) if (multisample_enabled) glDisable(GL_MULTISAMPLE_ARB); - /* we set this only once */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* scale fonts */ ui_fontscale(&style.paneltitle.points, block->aspect); ui_fontscale(&style.grouplabel.points, block->aspect); diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 235d7652539..53827a9a7bf 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -446,8 +446,6 @@ static void draw_scope_end(const rctf *rect, GLint *scissor) /* restore scissortest */ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* outline */ glColor4f(0.f, 0.f, 0.f, 0.5f); uiSetRoundBox(UI_CNR_ALL); @@ -460,14 +458,13 @@ static void histogram_draw_one(float r, float g, float b, float alpha, int i; if (is_line) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE); glLineWidth(1.5); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); glColor4f(r, g, b, alpha); /* curve outline */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_LINE_SMOOTH); glBegin(GL_LINE_STRIP); for (i = 0; i < res; i++) { @@ -477,14 +474,19 @@ static void histogram_draw_one(float r, float g, float b, float alpha, glEnd(); glDisable(GL_LINE_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glLineWidth(1.0); } else { /* under the curve */ + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glColor4f(r, g, b, alpha); glShadeModel(GL_FLAT); + glBegin(GL_QUAD_STRIP); glVertex2f(x, y); glVertex2f(x, y + (data[0] * h)); @@ -496,9 +498,11 @@ static void histogram_draw_one(float r, float g, float b, float alpha, glEnd(); /* curve outline */ + glColor4f(0.f, 0.f, 0.f, 0.25f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_LINE_SMOOTH); glBegin(GL_LINE_STRIP); for (i = 0; i < res; i++) { @@ -532,7 +536,6 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol) h = BLI_rctf_size_y(&rect) * hist->ymax; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.f, 0.f, 0.f, 0.3f); uiSetRoundBox(UI_CNR_ALL); @@ -619,8 +622,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), } glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + glColor4f(0.f, 0.f, 0.f, 0.3f); uiSetRoundBox(UI_CNR_ALL); uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); @@ -642,7 +644,6 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), BLF_draw_default(rect.xmin + 1, yofs - 5 + (i / 5.f) * h, 0, str, sizeof(str) - 1); /* in the loop because blf_draw reset it */ glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* 3 vertical separation */ if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) { @@ -665,15 +666,14 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) fdrawline(rect.xmin, yofs + h * 0.075f, rect.xmax + 1, yofs + h * 0.075f); + glBlendFunc(GL_ONE, GL_ONE); + if (scopes->ok && scopes->waveform_1 != NULL) { /* LUMA (1 channel) */ - glBlendFunc(GL_ONE, GL_ONE); glColor3f(alpha, alpha, alpha); if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { - glBlendFunc(GL_ONE, GL_ONE); - glPushMatrix(); glEnableClientState(GL_VERTEX_ARRAY); @@ -702,9 +702,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), SCOPES_WAVEFRM_YCC_JPEG)) { int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB); - - glBlendFunc(GL_ONE, GL_ONE); - + glPushMatrix(); glEnableClientState(GL_VERTEX_ARRAY); @@ -743,7 +741,9 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), } } } - + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + /* outline */ draw_scope_end(&rect, scissor); } @@ -838,7 +838,6 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.f, 0.f, 0.f, 0.3f); uiSetRoundBox(UI_CNR_ALL); @@ -890,6 +889,8 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); + + glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* outline */ @@ -1336,7 +1337,6 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti /* grid, hsv uses different grid */ glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(0, 0, 0, 48); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.1666666f); glDisable(GL_BLEND); @@ -1500,7 +1500,6 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc height = BLI_rctf_size_y(&rect); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* need scissor test, preview image can draw outside of boundary */ glGetIntegerv(GL_VIEWPORT, scissor); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 51dd9166e46..cc8fc941ae7 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -1129,9 +1129,7 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al #endif if (!iimg->rect) return; /* something has gone wrong! */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else if (di->type == ICON_TYPE_PREVIEW) { PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ff46925edaa..6d497fa474c 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -668,9 +668,6 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glDisable(GL_POLYGON_STIPPLE); - /* alpha fill */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4ubv((unsigned char *)wcol->inner); for (a = 0; a < wtb->totvert; a++) { diff --git a/source/blender/editors/mask/CMakeLists.txt b/source/blender/editors/mask/CMakeLists.txt index b1cf6db3144..033d034cf4e 100644 --- a/source/blender/editors/mask/CMakeLists.txt +++ b/source/blender/editors/mask/CMakeLists.txt @@ -25,10 +25,12 @@ set(INC ../include ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -48,4 +50,6 @@ set(SRC mask_intern.h ) +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_mask "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 7e767d8f6c8..8018d549b09 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -309,7 +309,6 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline if (is_smooth) { glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* control points */ @@ -498,7 +497,6 @@ static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (* if (is_smooth == false && is_feather) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } mask_color_active_tint(rgb_tmp, rgb_tmp, is_active); @@ -549,7 +547,6 @@ static void draw_spline_curve(const bContext *C, MaskLayer *masklay, MaskSpline if (is_smooth) { glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution(spline, &tot_feather_point, resol, (is_fill != false)); @@ -826,6 +823,7 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar, glPopMatrix(); if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) { + glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); } diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 0cb2dd1eb68..db20d42f39d 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -86,4 +87,6 @@ if(WITH_BULLET) add_definitions(-DWITH_BULLET) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_mesh "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 165af62c715..4828fa02d42 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -992,7 +992,6 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg) int i; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* draw any snapped verts first */ glColor4ubv(kcd->colors.point_a); diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt index 1bb35b65918..9b380ff8d48 100644 --- a/source/blender/editors/object/CMakeLists.txt +++ b/source/blender/editors/object/CMakeLists.txt @@ -33,10 +33,11 @@ set(INC ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS - + ${GLEW_INCLUDE_PATH} ) set(SRC @@ -62,6 +63,8 @@ set(SRC object_intern.h ) +add_definitions(${GL_DEFINITIONS}) + if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt index 892d71befb4..40d555226f3 100644 --- a/source/blender/editors/physics/CMakeLists.txt +++ b/source/blender/editors/physics/CMakeLists.txt @@ -23,11 +23,13 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/elbeem/extern ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -64,4 +66,6 @@ if(WITH_BULLET) add_definitions(-DWITH_BULLET) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_physics "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/render/CMakeLists.txt b/source/blender/editors/render/CMakeLists.txt index 24015bd4ea3..42dafc076ed 100644 --- a/source/blender/editors/render/CMakeLists.txt +++ b/source/blender/editors/render/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -64,6 +65,8 @@ if(WITH_HEADLESS) add_definitions(-DWITH_HEADLESS) endif() +add_definitions(${GL_DEFINITIONS}) + if(WITH_FREESTYLE) list(APPEND INC ../../freestyle diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index ecf5e962c80..559c86bf48c 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -31,8 +31,6 @@ #include <string.h> #include <stddef.h> -#include <GL/glew.h> - #include "MEM_guardedalloc.h" #include "BLI_math.h" @@ -69,6 +67,7 @@ #include "RNA_define.h" #include "GPU_extensions.h" +#include "GPU_glew.h" #include "wm_window.h" diff --git a/source/blender/editors/screen/CMakeLists.txt b/source/blender/editors/screen/CMakeLists.txt index 4ff1767f582..413d40b9f9c 100644 --- a/source/blender/editors/screen/CMakeLists.txt +++ b/source/blender/editors/screen/CMakeLists.txt @@ -30,6 +30,7 @@ set(INC ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -51,4 +52,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_screen "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 05418d8d451..aa0ae22a003 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -75,25 +75,24 @@ extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, static void region_draw_emboss(ARegion *ar, rcti *scirct) { rcti rect; - + /* translate scissor rect to region space */ rect.xmin = scirct->xmin - ar->winrct.xmin; rect.ymin = scirct->ymin - ar->winrct.ymin; rect.xmax = scirct->xmax - ar->winrct.xmin; rect.ymax = scirct->ymax - ar->winrct.ymin; - + /* set transp line */ glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + /* right */ glColor4ub(0, 0, 0, 30); sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax); - + /* bottom */ glColor4ub(0, 0, 0, 30); sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin); - + /* top */ glColor4ub(255, 255, 255, 30); sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax); @@ -101,7 +100,7 @@ static void region_draw_emboss(ARegion *ar, rcti *scirct) /* left */ glColor4ub(255, 255, 255, 30); sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax); - + glDisable(GL_BLEND); } @@ -338,7 +337,6 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar) return; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); glTranslatef(-ar->winrct.xmin, -ar->winrct.ymin, 0.0f); @@ -1922,7 +1920,6 @@ void ED_region_info_draw(ARegion *ar, const char *text, int block, float fill_co BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4fv(fill_color); glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1); glDisable(GL_BLEND); diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 5beab9fcc14..290923b2331 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -990,7 +990,6 @@ static void draw_join_shape(ScrArea *sa, char dir) /* draw screen area darker with arrow (visualization of future joining) */ static void scrarea_draw_shape_dark(ScrArea *sa, char dir) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glColor4ub(0, 0, 0, 50); draw_join_shape(sa, dir); @@ -1006,6 +1005,7 @@ static void scrarea_draw_shape_light(ScrArea *sa, char UNUSED(dir)) glColor4ub(255, 255, 255, 50); /* draw_join_shape(sa, dir); */ glRecti(sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); } diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index 18db57c9f21..0fa5f2d9837 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -64,4 +65,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_sculpt_paint "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_action/CMakeLists.txt b/source/blender/editors/space_action/CMakeLists.txt index e0dc2709cf3..96a1e74c882 100644 --- a/source/blender/editors/space_action/CMakeLists.txt +++ b/source/blender/editors/space_action/CMakeLists.txt @@ -22,10 +22,12 @@ set(INC ../include ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -42,4 +44,6 @@ set(SRC action_intern.h ) +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_action "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_buttons/CMakeLists.txt b/source/blender/editors/space_buttons/CMakeLists.txt index 9e045a39a0c..01a099e3701 100644 --- a/source/blender/editors/space_buttons/CMakeLists.txt +++ b/source/blender/editors/space_buttons/CMakeLists.txt @@ -23,10 +23,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -46,6 +48,8 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) endif() diff --git a/source/blender/editors/space_clip/CMakeLists.txt b/source/blender/editors/space_clip/CMakeLists.txt index 7689aa28169..4659e612b41 100644 --- a/source/blender/editors/space_clip/CMakeLists.txt +++ b/source/blender/editors/space_clip/CMakeLists.txt @@ -27,11 +27,12 @@ set(INC ../../blenfont ../../blenlib ../../imbuf + ../../gpu ../../makesdna ../../makesrna ../../windowmanager - ../../gpu ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -56,6 +57,8 @@ set(SRC clip_intern.h ) +add_definitions(${GL_DEFINITIONS}) + if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index a35251e71ef..cf7032cbe2d 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -155,7 +155,6 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* cache background */ ED_region_cache_draw_background(ar); @@ -293,7 +292,6 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, /* checkerboard for case alpha */ if (ibuf->planes == 32) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y); } @@ -1074,7 +1072,6 @@ static void draw_plane_marker_image(Scene *scene, if (plane_track->image_opacity != 1.0f || ibuf->planes == 32) { transparent = true; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index a79ac1f7b82..a5b6b07e1b2 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -330,7 +330,6 @@ void clip_draw_sfra_efra(View2D *v2d, Scene *scene) UI_view2d_view_ortho(v2d); /* currently clip editor supposes that editing clip length is equal to scene frame range */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glColor4f(0.0f, 0.0f, 0.0f, 0.4f); diff --git a/source/blender/editors/space_console/CMakeLists.txt b/source/blender/editors/space_console/CMakeLists.txt index 241a48c1e2d..ecfb1f0e0df 100644 --- a/source/blender/editors/space_console/CMakeLists.txt +++ b/source/blender/editors/space_console/CMakeLists.txt @@ -23,10 +23,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -45,4 +47,6 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_console "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_file/CMakeLists.txt b/source/blender/editors/space_file/CMakeLists.txt index 3b2db3ee7bc..fc007a659b4 100644 --- a/source/blender/editors/space_file/CMakeLists.txt +++ b/source/blender/editors/space_file/CMakeLists.txt @@ -25,11 +25,13 @@ set(INC ../../blenlib ../../blenloader ../../imbuf + ../../gpu ../../makesdna ../../makesrna ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -86,6 +88,8 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) endif() diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 3e099b43a4b..f6f11316a04 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -358,8 +358,6 @@ static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int xco = sx + (int)dx; yco = sy - layout->prv_h + (int)dy; - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* shadow */ if (dropshadow) uiDrawBoxShadow(220, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey)); diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt index d3fb87204fb..0a29810ff3d 100644 --- a/source/blender/editors/space_graph/CMakeLists.txt +++ b/source/blender/editors/space_graph/CMakeLists.txt @@ -23,10 +23,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -56,4 +58,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_graph "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index ed7cfe7da99..02ab73eee6c 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -1115,7 +1115,6 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) y = (float)ACHANNEL_FIRST; /* set blending again, as may not be set in previous step */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) { diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt index 62ac3c2d985..30bfc2fbdfd 100644 --- a/source/blender/editors/space_image/CMakeLists.txt +++ b/source/blender/editors/space_image/CMakeLists.txt @@ -23,14 +23,15 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib - ../../imbuf ../../bmesh + ../../imbuf + ../../gpu ../../makesdna ../../makesrna ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc - ../../gpu + ../../../../intern/glew-mx ) set(INC_SYS @@ -71,4 +72,6 @@ if(WITH_IMAGE_CINEON) add_definitions(-DWITH_CINEON) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_image "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 79c21bab01c..b069e50e5d7 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -151,7 +151,6 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d float hue = 0, sat = 0, val = 0, lum = 0, u = 0, v = 0; float col[4], finalcol[4]; - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* noisy, high contrast make impossible to read if lower alpha is used. */ @@ -312,7 +311,6 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d glRecti(color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(UNPACK3(finalcol), fp ? fp[3] : (cp[3] / 255.0f)); glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); glDisable(GL_BLEND); @@ -494,7 +492,6 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, else { if (sima->flag & SI_USE_ALPHA) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); fdrawcheckerboard(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy); } @@ -749,7 +746,6 @@ static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scen glPixelZoom(zoomx, zoomy); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, clonerect); glDisable(GL_BLEND); @@ -881,7 +877,6 @@ void draw_image_cache(const bContext *C, ARegion *ar) } glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* Draw cache background. */ ED_region_cache_draw_background(ar); diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt index 94b40a9f40a..46ea251de03 100644 --- a/source/blender/editors/space_info/CMakeLists.txt +++ b/source/blender/editors/space_info/CMakeLists.txt @@ -26,10 +26,12 @@ set(INC ../../blenloader ../../imbuf ../../bmesh + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -52,4 +54,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_info "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index 33333e4c992..4cbfce0f6e9 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -79,7 +79,6 @@ static void console_draw_sel(const char *str, const int sel[2], const int xy[2], const int end = txt_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ubv(bg_sel); glRecti(xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2); diff --git a/source/blender/editors/space_logic/CMakeLists.txt b/source/blender/editors/space_logic/CMakeLists.txt index af2e8476511..19525c87923 100644 --- a/source/blender/editors/space_logic/CMakeLists.txt +++ b/source/blender/editors/space_logic/CMakeLists.txt @@ -24,10 +24,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -47,6 +49,8 @@ if(WITH_GAMEENGINE) add_definitions(-DWITH_GAMEENGINE) endif() +add_definitions(${GL_DEFINITIONS}) + if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() diff --git a/source/blender/editors/space_nla/CMakeLists.txt b/source/blender/editors/space_nla/CMakeLists.txt index a74fc3191b7..ab0dfa30121 100644 --- a/source/blender/editors/space_nla/CMakeLists.txt +++ b/source/blender/editors/space_nla/CMakeLists.txt @@ -23,10 +23,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -49,4 +51,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_nla "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index ac8dca6e83a..65b768175b1 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -285,7 +285,6 @@ static void nla_draw_strip(SpaceNla *snla, AnimData *adt, NlaTrack *nlt, NlaStri */ if ((strip->extendmode != NLASTRIP_EXTEND_NOTHING) && (nonSolo == 0)) { /* enable transparency... */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); switch (strip->extendmode) { @@ -574,7 +573,6 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *ar) /* just draw a semi-shaded rect spanning the width of the viewable area if there's data, * and a second darker rect within which we draw keyframe indicator dots if there's data */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* get colors for drawing */ @@ -676,7 +674,6 @@ void draw_nla_channel_list(bContext *C, bAnimContext *ac, ARegion *ar) y = (float)(-NLACHANNEL_HEIGHT(snla)); /* set blending again, as may not be set in previous step */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* loop through channels, and set up drawing depending on their type */ diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index 6b0460ce5cd..34887f8388d 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../../windowmanager ../../compositor ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -64,4 +65,6 @@ if(WITH_COMPOSITOR) add_definitions(-DWITH_COMPOSITOR) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_node "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index b760d9f5aa8..86f9bc5d768 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -3105,7 +3105,6 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b } else if (snode->flag & SNODE_USE_ALPHA) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPixelZoom(snode->zoom, snode->zoom); glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST); diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 7b5ec38f4c6..52c1cefbfed 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -710,7 +710,6 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv) node_draw_preview_background(BLI_rctf_size_x(prv) / 10.0f, &draw_rect); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* premul graphics */ glColor4f(1.0, 1.0, 1.0, 1.0); glPixelZoom(scale, scale); @@ -1275,7 +1274,6 @@ void drawnodespace(const bContext *C, ARegion *ar) ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); /* only set once */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_MAP1_VERTEX_3); /* nodes */ diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index 4db47b75502..b716f0671bd 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -24,10 +24,12 @@ set(INC ../../blenlib ../../blenfont ../../imbuf + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -50,4 +52,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_outliner "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 7eb90953df4..0db7a90e313 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -1508,8 +1508,6 @@ static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegio TreeElement *te; int starty, startx; float col[3]; - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // only once if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) { /* struct marks */ diff --git a/source/blender/editors/space_script/CMakeLists.txt b/source/blender/editors/space_script/CMakeLists.txt index 26c4183f7df..2eb31576c57 100644 --- a/source/blender/editors/space_script/CMakeLists.txt +++ b/source/blender/editors/space_script/CMakeLists.txt @@ -22,10 +22,12 @@ set(INC ../include ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -47,4 +49,6 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_script "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt index db5729a5762..4cf9c0c95c2 100644 --- a/source/blender/editors/space_sequencer/CMakeLists.txt +++ b/source/blender/editors/space_sequencer/CMakeLists.txt @@ -24,10 +24,12 @@ set(INC ../../blenkernel ../../blenlib ../../imbuf + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -60,4 +62,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_sequencer "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index dab51f752b4..0dff2242b28 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -274,7 +274,6 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float draw_height; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (seqm->flag & SEQ_MUTE) drawmeta_stipple(1); @@ -376,8 +375,6 @@ static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_cla { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80); else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30); else glColor4ub(0, 0, 0, 22); @@ -437,7 +434,6 @@ static void draw_seq_extensions(Scene *scene, ARegion *ar, Sequence *seq) if (seq->startofs) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); get_seq_color3ubv(scene, seq, col); @@ -461,7 +457,6 @@ static void draw_seq_extensions(Scene *scene, ARegion *ar, Sequence *seq) } if (seq->endofs) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); get_seq_color3ubv(scene, seq, col); @@ -1058,7 +1053,6 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { if (sseq->flag & SEQ_USE_ALPHA) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); fdrawcheckerboard(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax); glColor4f(1.0, 1.0, 1.0, 1.0); diff --git a/source/blender/editors/space_text/CMakeLists.txt b/source/blender/editors/space_text/CMakeLists.txt index bfeeb93372a..5367efbf84b 100644 --- a/source/blender/editors/space_text/CMakeLists.txt +++ b/source/blender/editors/space_text/CMakeLists.txt @@ -23,10 +23,12 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -48,6 +50,8 @@ set(SRC text_intern.h ) +add_definitions(${GL_DEFINITIONS}) + if(WITH_PYTHON) list(APPEND INC ../../python diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 95802be9ef9..480696760d4 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1147,8 +1147,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar) x2 = x1 + ar->winx; glColor4ub(255, 255, 255, 32); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); glRecti(x1 - 4, y1, x2, y2); glDisable(GL_BLEND); diff --git a/source/blender/editors/space_time/CMakeLists.txt b/source/blender/editors/space_time/CMakeLists.txt index b42ae3ab725..90af405eaa8 100644 --- a/source/blender/editors/space_time/CMakeLists.txt +++ b/source/blender/editors/space_time/CMakeLists.txt @@ -22,10 +22,12 @@ set(INC ../include ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -39,4 +41,6 @@ set(SRC time_intern.h ) +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_space_time "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c index 2fd4b0bc21d..4c1e7256583 100644 --- a/source/blender/editors/space_time/space_time.c +++ b/source/blender/editors/space_time/space_time.c @@ -70,7 +70,6 @@ static void time_draw_sfra_efra(Scene *scene, View2D *v2d) /* draw darkened area outside of active timeline * frame range used is preview range or scene range */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glColor4f(0.0f, 0.0f, 0.0f, 0.4f); diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt index 97c328dbac2..320267a4a7c 100644 --- a/source/blender/editors/space_view3d/CMakeLists.txt +++ b/source/blender/editors/space_view3d/CMakeLists.txt @@ -31,6 +31,7 @@ set(INC ../../render/extern/include ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ../../../../intern/smoke/extern ) @@ -76,7 +77,7 @@ if(WITH_GAMEENGINE) add_definitions(-DWITH_GAMEENGINE) endif() -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index fb97a6ac9f4..1d54cb0cff9 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -178,7 +178,6 @@ void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm) /* Draw Selected Faces */ if (me->drawflag & ME_DRAWFACES) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* dull unselected faces so as not to get in the way of seeing color */ glColor4ub(96, 96, 96, 64); dm->drawMappedFaces(dm, draw_mesh_face_select__drawFaceOptsInv, NULL, NULL, (void *)me, 0); @@ -953,9 +952,6 @@ static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d /* reset from negative scale correction */ glFrontFace(GL_CCW); - - /* in editmode, the blend mode needs to be set in case it was ADD */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /************************** NEW SHADING NODES ********************************/ diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 75d64e93d59..5694f388780 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -660,7 +660,6 @@ static void draw_empty_image(Object *ob, const short dflag, const unsigned char int zoomfilter = (U.gameflags & USER_DISABLE_MIPMAP ) ? GL_NEAREST : GL_LINEAR; /* Setup GL params */ glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (use_clip) { glEnable(GL_ALPHA_TEST); @@ -7208,9 +7207,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short /* -------------------------------------------------------------------- */ /* no return after this point, otherwise leaks */ - /* only once set now, will be removed too, should become a global standard */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - view3d_cached_text_draw_begin(); /* draw motion paths (in view space) */ diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 59798f97d93..59f15395fd4 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -489,6 +489,11 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, n++; } + if (GLEW_VERSION_1_4) + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + //else + //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + #ifdef DEBUG_DRAW_TIME printf("Draw Time: %f\n", (float)TIMEIT_VALUE(draw)); TIMEIT_END(draw); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 004b3e1b7d3..be3aaa13818 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -597,7 +597,6 @@ static void draw_view_axis(RegionView3D *rv3d, rcti *rect) glLineWidth(2); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for (i = 0; i < 3; i++) { zero_v3(vec); @@ -639,7 +638,6 @@ static void draw_rotation_guide(RegionView3D *rv3d) negate_v3_v3(o, rv3d->ofs); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel(GL_SMOOTH); glPointSize(5); glEnable(GL_POINT_SMOOTH); @@ -745,7 +743,6 @@ static void draw_view_icon(RegionView3D *rv3d, rcti *rect) else return; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); UI_icon_draw(5.0 + rect->xmin, 5.0 + rect->ymin, icon); @@ -1095,7 +1092,6 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) glColor3f(0, 0, 0); } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glColor4f(0, 0, 0, ca->passepartalpha); } @@ -1797,7 +1793,6 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, glDepthMask(0); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glPushMatrix(); diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index 3ad5d94efd6..0c360474b78 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -30,6 +30,7 @@ set(INC ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -54,4 +55,6 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_transform "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 008022a9859..9092dbd52dd 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1852,7 +1852,6 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar) #endif /* autokey recording icon... */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); xco -= U.widget_unit; @@ -6136,7 +6135,6 @@ static void drawEdgeSlide(const struct bContext *C, TransInfo *t) glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT | GL_POINT_BIT); glPushMatrix(); @@ -6674,7 +6672,6 @@ static void drawVertSlide(const struct bContext *C, TransInfo *t) glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT | GL_POINT_BIT); glPushMatrix(); diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 2daaa102ea9..6441071056f 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -1663,7 +1663,6 @@ void BIF_draw_manipulator(const bContext *C) if (v3d->twflag & V3D_DRAW_MANIPULATOR) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); if (v3d->twtype & V3D_MANIP_ROTATE) { diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 4400870f1b8..f4189a18da4 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -24,10 +24,12 @@ set(INC ../../blenkernel ../../blenlib ../../bmesh + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -91,7 +93,7 @@ set(SRC ../include/UI_view2d.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt index 45edbde7482..74ba1672485 100644 --- a/source/blender/editors/uvedit/CMakeLists.txt +++ b/source/blender/editors/uvedit/CMakeLists.txt @@ -24,10 +24,12 @@ set(INC ../../blenlib ../../blenfont ../../bmesh + ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -57,4 +59,6 @@ if(WITH_OPENNL) ) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_editor_uvedit "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 36c96a8d011..8d46d9ac7cf 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -619,7 +619,6 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) /* draw transparent faces */ UI_GetThemeColor4ubv(TH_FACE, col1); UI_GetThemeColor4ubv(TH_FACE_SELECT, col2); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); #ifdef USE_EDBM_LOOPTRIS @@ -707,7 +706,6 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) tf = BM_ELEM_CD_GET_VOID_P(activef, cd_poly_tex_offset); if (uvedit_face_visible_test(scene, ima, activef, tf)) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); UI_ThemeColor4(TH_EDITMESH_ACTIVE); glEnable(GL_POLYGON_STIPPLE); @@ -731,7 +729,6 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) if (sima->flag & SI_SMOOTH_UV) { glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } switch (sima->dt_uv) { diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 13e46bc7de8..7d34c4e3829 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -37,6 +37,7 @@ set(INC ../nodes/intern ../../../intern/guardedalloc + ../../../intern/glew-mx ../../../intern/smoke/extern ) @@ -44,32 +45,125 @@ set(INC_SYS ${GLEW_INCLUDE_PATH} ) +set(INTERN_INC + intern/gpu_aspect_intern.h + intern/gpu_basic_intern.h + intern/gpu_blender_aspect_intern.h + intern/gpu_clipping_intern.h + intern/gpu_common_intern.h + intern/gpu_codegen.h + intern/gpu_extensions_intern.h + intern/gpu_immediate_intern.h + intern/gpu_lighting_intern.h + intern/gpu_pixels_intern.h + intern/gpu_primitives_inline.h + intern/gpu_profile.h + intern/gpu_raster_intern.h + intern/gpu_select_intern.h + intern/gpu_sprite_intern.h + intern/gpu_state_latch_intern.h +) + +set(GLSL_SRC + shaders/gpu_shader_vertex.glsl + shaders/gpu_shader_material.glsl + + shaders/gpu_shader_sep_gaussian_blur_frag.glsl + shaders/gpu_shader_sep_gaussian_blur_vert.glsl + + shaders/gpu_shader_vsm_store_frag.glsl + shaders/gpu_shader_vsm_store_vert.glsl + + shaders/gpu_shader_common_attribs.glsl + shaders/gpu_shader_common_constants.glsl + shaders/gpu_shader_common_uniforms.glsl + + shaders/gpu_shader_font_frag.glsl + shaders/gpu_shader_font_vert.glsl + + shaders/gpu_shader_pixels_uniforms.glsl + shaders/gpu_shader_pixels_frag.glsl + shaders/gpu_shader_pixels_vert.glsl + + shaders/gpu_shader_basic_frag.glsl + shaders/gpu_shader_basic_vert.glsl + + shaders/gpu_shader_raster_frag.glsl + shaders/gpu_shader_raster_uniforms.glsl + shaders/gpu_shader_raster_vert.glsl +) + set(SRC + intern/gpu_aspect.c + intern/gpu_basic.c + intern/gpu_blender_aspect.c intern/gpu_buffers.c + intern/gpu_clipping.c intern/gpu_codegen.c + intern/gpu_common.c + intern/gpu_debug.c intern/gpu_draw.c intern/gpu_extensions.c + intern/gpu_font.c + intern/gpu_immediate.c + intern/gpu_immediate_gl.c + intern/gpu_init_exit.c + intern/gpu_lighting.c intern/gpu_material.c - intern/gpu_simple_shader.c + intern/gpu_matrix.c + intern/gpu_pixels.c + intern/gpu_primitives.c + intern/gpu_raster.c intern/gpu_select.c + intern/gpu_sprite.c + intern/gpu_state_latch.c + intern/gpu_utility.c + GPU_aspect.h + GPU_basic.h + GPU_blender_aspect.h GPU_buffers.h + GPU_clipping.h + GPU_colors.h + GPU_common.h + GPU_deprecated.h GPU_draw.h GPU_extensions.h + GPU_font.h + GPU_glew.h + GPU_init_exit.h + GPU_immediate.h + GPU_lighting.h GPU_material.h - GPU_simple_shader.h + GPU_matrix.h + GPU_pixels.h + GPU_primitives.h + GPU_raster.h + GPU_safety.h GPU_select.h - intern/gpu_codegen.h + GPU_sprite.h + GPU_state_latch.h + GPU_utility.h + + ${INTERN_INC} + + ${GLSL_SRC} ) -data_to_c_simple(shaders/gpu_shader_material.glsl SRC) -data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_simple_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_simple_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC) -data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC) +if(WITH_GPU_SAFETY) + list(APPEND SRC + intern/gpu_safety.c + ) +endif() + +foreach(GLSL_FILE ${GLSL_SRC}) + data_to_c_simple(${GLSL_FILE} SRC) + list(APPEND GEN_SRC "${CMAKE_CURRENT_BINARY_DIR}/${GLSL_FILE}.c") +endforeach() + +source_group("Internal Header Files" FILES ${INTERN_INC}) +source_group("Generated Files" FILES ${GEN_SRC}) +source_group("Shader Files" FILES ${GLSL_SRC}) if(WITH_GAMEENGINE) add_definitions(-DWITH_GAMEENGINE) @@ -79,12 +173,10 @@ if(WITH_MOD_SMOKE) add_definitions(-DWITH_SMOKE) endif() -add_definitions(-DGLEW_STATIC) - if(WITH_IMAGE_DDS) add_definitions(-DWITH_DDS) endif() +add_definitions(${GL_DEFINITIONS}) blender_add_lib(bf_gpu "${SRC}" "${INC}" "${INC_SYS}") - diff --git a/source/blender/gpu/GPU_aspect.h b/source/blender/gpu/GPU_aspect.h new file mode 100644 index 00000000000..51327976d3a --- /dev/null +++ b/source/blender/gpu/GPU_aspect.h @@ -0,0 +1,73 @@ +#ifndef _GPU_ASPECT_H_ +#define _GPU_ASPECT_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_aspect.h + * \ingroup gpu + */ + +#include "BLI_sys_types.h" + +#include <string.h> /* for size_t */ + +#ifdef __cplusplus +extern "C" { +#endif + +void GPU_gen_aspects (size_t count, uint32_t* aspects); +void GPU_delete_aspects(size_t count, const uint32_t* aspects); + +typedef struct GPUaspectimpl { + bool (*render_begin )(const void* object, void* param); + bool (*render_end )(const void* object, void* param); + bool (*render_commit)(const void* object); + bool (*select_begin )(const void* object, void* param); + bool (*select_end )(const void* object, void* param); + bool (*select_commit)(const void* object); + void (*enable )(const void* object, uint32_t options); + void (*disable )(const void* object, uint32_t options); + void* object; + void* current_param; /* not a part of the interface */ +} GPUaspectimpl; + +void GPU_aspect_impl(uint32_t aspect, GPUaspectimpl* aspectImpl); + +bool GPU_aspect_begin(uint32_t aspect, void* param); +bool GPU_aspect_end (void); + +void GPU_aspect_enable (uint32_t aspect, uint32_t options); +void GPU_aspect_disable(uint32_t aspect, uint32_t options); + +bool GPU_commit_aspect(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_ASPECT_H_ */ diff --git a/source/blender/gpu/GPU_basic.h b/source/blender/gpu/GPU_basic.h new file mode 100644 index 00000000000..161ad6baf5a --- /dev/null +++ b/source/blender/gpu/GPU_basic.h @@ -0,0 +1,70 @@ +#ifndef _GPU_BASIC_H_ +#define _GPU_BASIC_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Brecht Van Lommel, Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_basic.h + * \ingroup gpu + */ + +#include "BLI_sys_types.h" /* for bool */ + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +typedef enum GPUBasicOption { + GPU_BASIC_LIGHTING = (1<<0), /* do lighting computations */ + GPU_BASIC_TWO_SIDE = (1<<1), /* flip back-facing normals towards viewer */ + GPU_BASIC_TEXTURE_2D = (1<<2), /* use 2D texture to replace diffuse color */ + GPU_BASIC_LOCAL_VIEWER = (1<<3), /* use for orthographic projection */ + GPU_BASIC_SMOOTH = (1<<4), /* use smooth shading */ + GPU_BASIC_ALPHATEST = (1<<5), /* use alpha test */ + GPU_BASIC_CLIPPING = (1<<6), /* use clipping */ + + GPU_BASIC_FAST_LIGHTING = (1<<7), /* use faster lighting (set automatically) */ + + GPU_BASIC_OPTIONS_NUM = 8, + GPU_BASIC_OPTION_COMBINATIONS = (1<<GPU_BASIC_OPTIONS_NUM) +} GPUBasicOption; + + + +bool GPU_basic_needs_normals(void); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_BASIC_H_ */ diff --git a/source/blender/gpu/GPU_blender_aspect.h b/source/blender/gpu/GPU_blender_aspect.h new file mode 100644 index 00000000000..41b5e68d392 --- /dev/null +++ b/source/blender/gpu/GPU_blender_aspect.h @@ -0,0 +1,55 @@ +#ifndef _GPU_BLENDER_ASPECT_H_ +#define _GPU_BLENDER_ASPECT_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_blender_aspect.h + * \ingroup gpu + */ + +#include "GPU_aspect.h" + + + +extern uint32_t GPU_ASPECT_BASIC; +extern uint32_t GPU_ASPECT_CODEGEN; +extern uint32_t GPU_ASPECT_FONT; +extern uint32_t GPU_ASPECT_PIXELS; +extern uint32_t GPU_ASPECT_RASTER; +extern uint32_t GPU_ASPECT_SPRITE; + +extern GPUaspectimpl GPU_ASPECTIMPL_BASIC; +extern GPUaspectimpl GPU_ASPECTIMPL_CODEGEN; +extern GPUaspectimpl GPU_ASPECTIMPL_FONT; +extern GPUaspectimpl GPU_ASPECTIMPL_PIXELS; +extern GPUaspectimpl GPU_ASPECTIMPL_RASTER; +extern GPUaspectimpl GPU_ASPECTIMPL_SPRITE; + + + +#endif /* _GPU_BLENDER_ASPECT_H_ */ diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index ba461d5f8a2..ee20919dde3 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -29,8 +29,14 @@ * \ingroup gpu */ -#ifndef __GPU_BUFFERS_H__ -#define __GPU_BUFFERS_H__ +#ifndef _GPU_BUFFERS_H_ +#define _GPU_BUFFERS_H_ + +#include "BKE_DerivedMesh.h" + +#ifdef __cplusplus +extern "C" { +#endif #ifdef DEBUG /* #define DEBUG_VBO(X) printf(X)*/ @@ -40,15 +46,8 @@ #endif struct BMesh; -struct CCGElem; -struct CCGKey; -struct CustomData; -struct DMFlagMat; -struct DerivedMesh; struct GHash; struct GSet; -struct GPUVertPointLink; -struct PBVH; typedef struct GPUBuffer { int size; /* in bytes */ @@ -180,8 +179,8 @@ GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading); /* update */ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert, - int *vert_indices, int totvert, const float *vmask, - int (*face_vert_indices)[4], bool show_diffuse_color); + int *vert_indices, int totvert, const float *vmask, + int (*face_vert_indices)[4], bool show_diffuse_color); void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, struct BMesh *bm, @@ -208,4 +207,10 @@ bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, struct GSet *bm void GPU_free_pbvh_buffers(GPU_PBVH_Buffers *buffers); + + +#ifdef __cplusplus +} +#endif + #endif diff --git a/source/blender/gpu/GPU_clipping.h b/source/blender/gpu/GPU_clipping.h new file mode 100644 index 00000000000..519f3a93ce2 --- /dev/null +++ b/source/blender/gpu/GPU_clipping.h @@ -0,0 +1,57 @@ +#ifndef _GPU_CLIPPING_H_ +#define _GPU_CLIPPING_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2014 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_clipping.h + * \ingroup gpu + */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct GPUplane { + double equation[4]; +} GPUplane; + +/* Set clipping planes and also applies appropriate transformations */ +void GPU_set_clip_planes(int clip_plane_count, const GPUplane clip_planes[]); + +int GPU_get_clip_planes(GPUplane clip_planes_out[]); + +/* Set clip planes without transforming them. + Suitable for restoring a backup copy of previous clip plane state. + Keeps clip planes from getting transformed twice. */ +void GPU_restore_clip_planes(int clip_plane_count, const GPUplane clip_planes[]); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_CLIPPING_H_ */ diff --git a/source/blender/gpu/GPU_colors.h b/source/blender/gpu/GPU_colors.h new file mode 100644 index 00000000000..068befc7ada --- /dev/null +++ b/source/blender/gpu/GPU_colors.h @@ -0,0 +1,46 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_colors.h + * \ingroup gpu + */ + +#ifndef __GPU_COLORS__ +#define __GPU_COLORS__ + +#define CPACK_BLACK 0x000000 +#define CPACK_WHITE 0xFFFFFF + +#define CPACK_RED 0xFF0000 +#define CPACK_GREEN 0x00FF00 +#define CPACK_BLUE 0x0000FF + +#define CPACK_YELLOW 0xFFFF00 +#define CPACK_CYAN 0x00FFFF +#define CPACK_MAGENTA 0xFF00FF + +#endif diff --git a/source/blender/gpu/GPU_common.h b/source/blender/gpu/GPU_common.h new file mode 100644 index 00000000000..db4d47f85ef --- /dev/null +++ b/source/blender/gpu/GPU_common.h @@ -0,0 +1,84 @@ +#ifndef _GPU_COMMON_H_ +#define _GPU_COMMON_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_common.h + * \ingroup gpu + */ + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +// XXX jwilkins: do these belong here? +#define GPU_MAX_COMMON_TEXCOORDS 1 +#define GPU_MAX_COMMON_SAMPLERS 1 +#define GPU_MAX_COMMON_LIGHTS 8 +#define GPU_MAX_COMMON_CLIP_PLANES 6 + + + +/* for setting up the common vertex attributes */ + +void GPU_common_enable_vertex_array (void); +void GPU_common_enable_normal_array (void); +void GPU_common_enable_color_array (void); +void GPU_common_enable_texcoord_array(void); + +void GPU_common_disable_vertex_array (void); +void GPU_common_disable_normal_array (void); +void GPU_common_disable_color_array (void); +void GPU_common_disable_texcoord_array(void); + +void GPU_common_vertex_pointer (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); +void GPU_common_normal_pointer ( GLenum type, GLsizei stride, GLboolean normalized, const GLvoid* pointer); +void GPU_common_color_pointer (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); +void GPU_common_texcoord_pointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); + +void GPU_set_common_active_texture(GLint texture); +GLint GPU_get_common_active_texture(void); + +void GPU_common_normal_3fv(GLfloat n[3]); + +void GPU_common_color_4ubv(GLubyte c[4]); +void GPU_common_color_4fv (GLfloat c[4]); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_COMMON_H_ */ diff --git a/source/blender/gpu/GPU_deprecated.h b/source/blender/gpu/GPU_deprecated.h new file mode 100644 index 00000000000..9438b4fab82 --- /dev/null +++ b/source/blender/gpu/GPU_deprecated.h @@ -0,0 +1,877 @@ +#ifndef _GPU_DEPRECATED_H_ +#define _GPU_DEPRECATED_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins, Alexandr Kuznetsov + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_deprecated.h + * \ingroup gpu + */ + +#undef glAttachShader +#define glAttachShader USE_SHIM_gpu_glAttachShader +#undef glCompileShader +#define glCompileShader USE_SHIM_gpu_glCompileShader +#undef glCreateProgram +#define glCreateProgram USE_SHIM_gpu_glCreateProgram +#undef glCreateShader +#define glCreateShader USE_SHIM_gpu_glCreateShader +#undef glDeleteShader +#define glDeleteShader USE_SHIM_gpu_glDeleteShader +#undef glGetProgramInfoLog +#define glGetProgramInfoLog USE_SHIM_gpu_glGetProgramInfoLog +#undef glGetShaderiv +#define glGetShaderiv USE_SHIM_gpu_glGetShaderiv +#undef glGetShaderInfoLog +#define glGetShaderInfoLog USE_SHIM_gpu_glGetShaderInfoLog +#undef glGetUniformLocation +#define glGetUniformLocation USE_SHIM_gpu_glGetUniformLocation +#undef glLinkProgram +#define glLinkProgram USE_SHIM_gpu_glLinkProgram +#undef glShaderSource +#define glShaderSource USE_SHIM_gpu_glShaderSource +#undef glUniform1i +#define glUniform1i USE_SHIM_gpu_glUniform1i +#undef glUniform1f +#define glUniform1f USE_SHIM_gpu_glUniform1f +#undef glUniform1iv +#define glUniform1iv USE_SHIM_gpu_glUniform1iv +#undef glUniform2iv +#define glUniform2iv USE_SHIM_gpu_glUniform2iv +#undef glUniform3iv +#define glUniform3iv USE_SHIM_gpu_glUniform3iv +#undef glUniform4iv +#define glUniform4iv USE_SHIM_gpu_glUniform4iv +#undef glUniform1fv +#define glUniform1fv USE_SHIM_gpu_glUniform1fv +#undef glUniform2fv +#define glUniform2fv USE_SHIM_gpu_glUniform2fv +#undef glUniform3fv +#define glUniform3fv USE_SHIM_gpu_glUniform3fv +#undef glUniform4fv +#define glUniform4fv USE_SHIM_gpu_glUniform4fv +#undef glUniformMatrix3fv +#define glUniformMatrix3fv USE_SHIM_gpu_glUniformMatrix3fv +#undef glUniformMatrix4fv +#define glUniformMatrix4fv USE_SHIM_gpu_glUniformMatrix4fv +#undef glUseProgram +#define glUseProgram USE_SHIM_gpu_glUseProgram +#undef glValidateProgram +#define glValidateProgram USE_SHIM_gpu_glValidateProgram + +#undef glAttachObjectARB +#define glAttachObjectARB USE_SHIM_gpu_glAttachObject +#undef glCompileShader +#define glCompileShader USE_SHIM_gpu_glCompileShader +#undef glCreateProgramObjectARB +#define glCreateProgramObjectARB USE_SHIM_gpu_glCreateProgram +#undef glCreateShaderObjectARB +#define glCreateShaderObjectARB USE_SHIM_gpu_glCreateShader +#undef glDeleteObjectARB +#define glDeleteObjectARB USE_SHIM_gpu_glDeleteShader_or_gpu_glDeleteProgram +#undef glGetInfoLogARB +#define glGetInfoLogARB USE_SHIM_gpu_glGetProgramInfoLog_or_gpu_glGetShaderInfoLog +#undef glGetObjectParameterivARB +#define glGetObjectParameterivARB USE_SHIM_gpu_glGetShaderiv +#undef glGetUniformLocationARB +#define glGetUniformLocationARB USE_SHIM_gpu_glGetUniformLocation +#undef glLinkProgramARB +#define glLinkProgramARB USE_SHIM_gpu_glLinkProgram +#undef glShaderSourceARB +#define glShaderSourceARB USE_SHIM_gpu_glShaderSource +#undef glUniform1iARB +#define glUniform1iARB USE_SHIM_gpu_glUniform1i +#undef glUniform1fARB +#define glUniform1fARB USE_SHIM_gpu_glUniform1f +#undef glUniform1ivARB +#define glUniform1ivARB USE_SHIM_gpu_glUniform1iv +#undef glUniform2ivARB +#define glUniform2ivARB USE_SHIM_gpu_glUniform2iv +#undef glUniform3ivARB +#define glUniform3ivARB USE_SHIM_gpu_glUniform3iv +#undef glUniform4ivARB +#define glUniform4ivARB USE_SHIM_gpu_glUniform4iv +#undef glUniform1fvARB +#define glUniform1fvARB USE_SHIM_gpu_glUniform1fv +#undef glUniform2fvARB +#define glUniform2fvARB USE_SHIM_gpu_glUniform2fv +#undef glUniform3fvARB +#define glUniform3fvARB USE_SHIM_gpu_glUniform3fv +#undef glUniform4fvARB +#define glUniform4fvARB USE_SHIM_gpu_glUniform4fv +#undef glUniformMatrix3fvARB +#define glUniformMatrix3fvARB USE_SHIM_gpu_glUniformMatrix3fv +#undef glUniformMatrix4fvARB +#define glUniformMatrix4fvARB USE_SHIM_gpu_glUniformMatrix4fv +#undef glUseProgramObjectARB +#define glUseProgramObjectARB USE_SHIM_gpu_glUseProgram +#undef glValidateProgramARB +#define glValidateProgramARB USE_SHIM_gpu_glValidateProgram + +#undef glBindAttribLocation +#define glBindAttribLocation USE_SHIM_gpu_glBindAttribLocation +#undef glGetAttribLocation +#define glGetAttribLocation USE_SHIM_gpu_glGetAttribLocation + +#undef glBindAttribLocationARB +#define glBindAttribLocationARB USE_SHIM_gpu_glBindAttribLocation +#undef glGetAttribLocationARB +#define glGetAttribLocationARB USE_SHIM_gpu_glGetAttribLocation + +#undef glDeleteProgram +#define glDeleteProgram USE_SHIM_gpu_glDeleteProgram +#undef glDisableVertexAttribArray +#define glDisableVertexAttribArray USE_SHIM_gpu_glDisableVertexAttribArray +#undef glEnableVertexAttribArray +#define glEnableVertexAttribArray USE_SHIM_gpu_glEnableVertexAttribArray +#undef glGetProgramiv +#define glGetProgramiv USE_SHIM_gpu_glGetProgramiv +#undef glVertexAttribPointer +#define glVertexAttribPointer USE_SHIM_gpu_glVertexAttribPointer + +//#undef glDeleteObjectARB +//#define glDeleteObjectARB USE_SHIM_gpu_glDeleteShader_or_gpu_glDeleteProgram +#undef glDisableVertexAttribArrayARB +#define glDisableVertexAttribArrayARB USE_SHIM_gpu_glDisableVertexAttribArray +#undef glEnableVertexAttribArrayARB +#define glEnableVertexAttribArrayARB USE_SHIM_gpu_glEnableVertexAttribArray +#undef glGetProgramivARB +#define glGetProgramiv USE_SHIM_gpu_glGetProgramiv +#undef glVertexAttribPointerARB +#define glVertexAttribPointerARB USE_SHIM_gpu_glVertexAttribPointer + +#undef glBindBuffer +#define glBindBuffer USE_SHIM_gpu_glBindBuffer +#undef glBufferData +#define glBufferData USE_SHIM_gpu_glBufferData +#undef glBufferSubData +#define glBufferSubData USE_SHIM_gpu_glBufferSubData +#undef glDeleteBuffers +#define glDeleteBuffers USE_SHIM_gpu_glDeleteBuffers +#undef glGenBuffers +#define glGenBuffers USE_SHIM_gpu_glGenBuffers + +#undef glBindBufferARB +#define glBindBufferARB USE_SHIM_gpu_glBindBuffer +#undef glBufferDataARB +#define glBufferDataARB USE_SHIM_gpu_glBufferData +#undef glBufferSubDataARB +#define glBufferSubDataARB USE_SHIM_gpu_glBufferSubData +#undef glDeleteBuffersARB +#define glDeleteBuffersARB USE_SHIM_gpu_glDeleteBuffers +#undef glGenBuffersARB +#define glGenBuffersARB USE_SHIM_gpu_glGenBuffers + +#undef glMapBuffer +#define glMapBuffer USE_SHIM_gpu_glMapBuffer +#undef glUnmapBuffer +#define glUnmapBuffer USE_SHIM_gpu_glUnmapBuffer + +#undef glMapBufferARB +#define glMapBufferARB USE_SHIM_gpu_glMapBuffer +#undef glUnmapBufferARB +#define glUnmapBufferARB USE_SHIM_gpu_glUnmapBuffer + +#undef glMapBufferOES +#define glMapBufferOES USE_SHIM_gpu_glMapBuffer +#undef glUnmapBufferOES +#define glUnmapBufferOES USE_SHIM_gpu_glUnmapBuffer + +#undef glBindFramebuffer +#define glBindFramebuffer USE_SHIM_gpu_glBindFramebuffer +#undef glCheckFramebufferStatus +#define glCheckFramebufferStatus USE_SHIM_gpu_glCheckFramebufferStatus +#undef glDeleteFramebuffers +#define glDeleteFramebuffers USE_SHIM_gpu_glDeleteFramebuffers +#undef glFramebufferTexture2D +#define glFramebufferTexture2D USE_SHIM_gpu_glFramebufferTexture2D +#undef glGenFramebuffers +#define glGenFramebuffers USE_SHIM_gpu_glGenFramebuffers + +#undef glBindFramebufferEXT +#define glBindFramebufferEXT USE_SHIM_gpu_glBindFramebuffer +#undef glCheckFramebufferStatusEXT +#define glCheckFramebufferStatusEXT USE_SHIM_gpu_glCheckFramebufferStatus +#undef glDeleteFramebuffersEXT +#define glDeleteFramebuffersEXT USE_SHIM_gpu_glDeleteFramebuffers +#undef glFramebufferTexture2DEXT +#define glFramebufferTexture2DEXT USE_SHIM_gpu_glFramebufferTexture2D +#undef glGenFramebuffersEXT +#define glGenFramebuffersEXT USE_SHIM_gpu_glGenFramebuffers + +#undef glBindFramebufferOES +#define glBindFramebufferOES USE_SHIM_gpu_glBindFramebuffer +#undef glCheckFramebufferStatusOES +#define glCheckFramebufferStatusOES USE_SHIM_gpu_glCheckFramebufferStatus +#undef glDeleteFramebuffersOES +#define glDeleteFramebuffersOES USE_SHIM_gpu_glDeleteFramebuffers +#undef glFramebufferTexture2DOES +#define glFramebufferTexture2DOES USE_SHIM_gpu_glFramebufferTexture2D +#undef glGenFramebuffersOES +#define glGenFramebuffersOES USE_SHIM_gpu_glGenFramebuffers + +#undef glBindVertexArray +#define glBindVertexArray USE_SHIM_gpu_glBindVertexArray +#undef glDeleteVertexArrays +#define glDeleteVertexArrays USE_SHIM_gpu_glDeleteVertexArrays +#undef glGenVertexArrays +#define glGenVertexArrays USE_SHIM_gpu_glGenVertexArrays + +#undef glBindVertexArrayOES +#define glBindVertexArrayOES USE_SHIM_gpu_glBindVertexArray +#undef glDeleteVertexArraysOES +#define glDeleteVertexArraysOES USE_SHIM_gpu_glDeleteVertexArrays +#undef glGenVertexArraysOES +#define glGenVertexArraysOES USE_SHIM_gpu_glGenVertexArrays + +#undef glGenerateMipmap +#define glGenerateMipmap USE_SHIM_gpu_glGenerateMipmap + +#undef glGenerateMipmapEXT +#define glGenerateMipmapEXT USE_SHIM_gpu_glGenerateMipmapEXT + +#undef glGenerateMipmapOES +#define glGenerateMipmapOES USE_SHIM_gpu_glGenerateMipmapOES + +#if 0 +#undef glBegin +#define glBegin DO_NOT_USE_glBegin +#undef glEnd +#define glEnd DO_NOT_USE_glEnd + +#undef glColor3b +#define glColor3b DO_NOT_USE_glColor3b +#undef glColor3bv +#define glColor3bv DO_NOT_USE_glColor3bv +#undef glColor3d +#define glColor3d DO_NOT_USE_glColor3d +#undef glColor3dv +#define glColor3dv DO_NOT_USE_glColor3dv +#undef glColor3f +#define glColor3f DO_NOT_USE_glColor3f +#undef glColor3fv +#define glColor3fv DO_NOT_USE_glColor3fv +#undef glColor3i +#define glColor3i DO_NOT_USE_glColor3i +#undef glColor3iv +#define glColor3iv DO_NOT_USE_glColor3iv +#undef glColor3s +#define glColor3s DO_NOT_USE_glColor3s +#undef glColor3sv +#define glColor3sv DO_NOT_USE_glColor3sv +#undef glColor3ub +#define glColor3ub DO_NOT_USE_glColor3ub +#undef glColor3ubv +#define glColor3ubv DO_NOT_USE_glColor3ubv +#undef glColor3ui +#define glColor3ui DO_NOT_USE_glColor3ui +#undef glColor3uiv +#define glColor3uiv DO_NOT_USE_glColor3uiv +#undef glColor3us +#define glColor3us DO_NOT_USE_glColor3us +#undef glColor3usv +#define glColor3usv DO_NOT_USE_glColor3usv +#undef glColor4b +#define glColor4b DO_NOT_USE_glColor4b +#undef glColor4bv +#define glColor4bv DO_NOT_USE_glColor4bv +#undef glColor4d +#define glColor4d DO_NOT_USE_glColor4d +#undef glColor4dv +#define glColor4dv DO_NOT_USE_glColor4dv +#undef glColor4f +#define glColor4f DO_NOT_USE_glColor4f +#undef glColor4fv +#define glColor4fv DO_NOT_USE_glColor4fv +#undef glColor4i +#define glColor4i DO_NOT_USE_glColor4i +#undef glColor4iv +#define glColor4iv DO_NOT_USE_glColor4iv +#undef glColor4s +#define glColor4s DO_NOT_USE_glColor4s +#undef glColor4sv +#define glColor4sv DO_NOT_USE_glColor4sv +#undef glColor4ub +#define glColor4ub DO_NOT_USE_glColor4ub +#undef glColor4ubv +#define glColor4ubv DO_NOT_USE_glColor4ubv +#undef glColor4ui +#define glColor4ui DO_NOT_USE_glColor4ui +#undef glColor4uiv +#define glColor4uiv DO_NOT_USE_glColor4uiv +#undef glColor4us +#define glColor4us DO_NOT_USE_glColor4us +#undef glColor4usv +#define glColor4usv DO_NOT_USE_glColor4usv + +#undef glEvalCoord1d +#define glEvalCoord1d DO_NOT_USE_glEvalCoord1d +#undef glEvalCoord1dv +#define glEvalCoord1dv DO_NOT_USE_glEvalCoord1dv +#undef glEvalCoord1f +#define glEvalCoord1f DO_NOT_USE_glEvalCoord1f +#undef glEvalCoord1fv +#define glEvalCoord1fv DO_NOT_USE_glEvalCoord1fv +#undef glEvalCoord2d +#define glEvalCoord2d DO_NOT_USE_glEvalCoord2d +#undef glEvalCoord2dv +#define glEvalCoord2dv DO_NOT_USE_glEvalCoord2dv +#undef glEvalCoord2f +#define glEvalCoord2f DO_NOT_USE_glEvalCoord2f +#undef glEvalCoord2fv +#define glEvalCoord2fv DO_NOT_USE_glEvalCoord2fv +#undef glEvalMesh1 +#define glEvalMesh1 DO_NOT_USE_glEvalMesh1 +#undef glEvalMesh2 +#define glEvalMesh2 DO_NOT_USE_glEvalMesh2 +#undef glEvalPoint1 +#define glEvalPoint1 DO_NOT_USE_glEvalPoint1 +#undef glEvalPoint2 +#define glEvalPoint2 DO_NOT_USE_glEvalPoint2 + +#undef glIndexd +#define glIndexd DO_NOT_USE_glIndexd +#undef glIndexdv +#define glIndexdv DO_NOT_USE_glIndexdv +#undef glIndexf +#define glIndexf DO_NOT_USE_glIndexf +#undef glIndexfv +#define glIndexfv DO_NOT_USE_glIndexfv +#undef glIndexi +#define glIndexi DO_NOT_USE_glIndexi +#undef glIndexiv +#define glIndexiv DO_NOT_USE_glIndexiv +#undef glIndexs +#define glIndexs DO_NOT_USE_glIndexs +#undef glIndexsv +#define glIndexsv DO_NOT_USE_glIndexsv +#undef glIndexub +#define glIndexub DO_NOT_USE_glIndexub +#undef glIndexubv +#define glIndexubv DO_NOT_USE_glIndexubv + +#undef glNormal3b +#define glNormal3b DO_NOT_USE_glNormal3b +#undef glNormal3bv +#define glNormal3bv DO_NOT_USE_glNormal3bv +#undef glNormal3d +#define glNormal3d DO_NOT_USE_glNormal3d +#undef glNormal3dv +#define glNormal3dv DO_NOT_USE_glNormal3dv +#undef glNormal3f +#define glNormal3f DO_NOT_USE_glNormal3f +#undef glNormal3fv +#define glNormal3fv DO_NOT_USE_glNormal3fv +#undef glNormal3i +#define glNormal3i DO_NOT_USE_glNormal3i +#undef glNormal3iv +#define glNormal3iv DO_NOT_USE_glNormal3iv +#undef glNormal3s +#define glNormal3s DO_NOT_USE_glNormal3s +#undef glNormal3sv +#define glNormal3sv DO_NOT_USE_glNormal3sv + +#undef glMaterialf +#define glMaterialf DO_NOT_USE_glMaterialf +#undef glMaterialfv +#define glMaterialfv DO_NOT_USE_glMaterialfv +#undef glMateriali +#define glMateriali DO_NOT_USE_glMateriali +#undef glMaterialiv +#define glMaterialiv DO_NOT_USE_glMaterialiv + +#undef glTexCoord1d +#define glTexCoord1d DO_NOT_USE_glTexCoord1d +#undef glTexCoord1dv +#define glTexCoord1dv DO_NOT_USE_glTexCoord1dv +#undef glTexCoord1f +#define glTexCoord1f DO_NOT_USE_glTexCoord1f +#undef glTexCoord1fv +#define glTexCoord1fv DO_NOT_USE_glTexCoord1fv +#undef glTexCoord1i +#define glTexCoord1i DO_NOT_USE_glTexCoord1i +#undef glTexCoord1iv +#define glTexCoord1iv DO_NOT_USE_glTexCoord1iv +#undef glTexCoord1s +#define glTexCoord1s DO_NOT_USE_glTexCoord1s +#undef glTexCoord1sv +#define glTexCoord1sv DO_NOT_USE_glTexCoord1sv +#undef glTexCoord2d +#define glTexCoord2d DO_NOT_USE_glTexCoord2d +#undef glTexCoord2dv +#define glTexCoord2dv DO_NOT_USE_glTexCoord2dv +#undef glTexCoord2f +#define glTexCoord2f DO_NOT_USE_glTexCoord2f +#undef glTexCoord2fv +#define glTexCoord2fv DO_NOT_USE_glTexCoord2fv +#undef glTexCoord2i +#define glTexCoord2i DO_NOT_USE_glTexCoord2i +#undef glTexCoord2iv +#define glTexCoord2iv DO_NOT_USE_glTexCoord2iv +#undef glTexCoord2s +#define glTexCoord2s DO_NOT_USE_glTexCoord2s +#undef glTexCoord2sv +#define glTexCoord2sv DO_NOT_USE_glTexCoord2sv +#undef glTexCoord3d +#define glTexCoord3d DO_NOT_USE_glTexCoord3d +#undef glTexCoord3dv +#define glTexCoord3dv DO_NOT_USE_glTexCoord3dv +#undef glTexCoord3f +#define glTexCoord3f DO_NOT_USE_glTexCoord3f +#undef glTexCoord3fv +#define glTexCoord3fv DO_NOT_USE_glTexCoord3fv +#undef glTexCoord3i +#define glTexCoord3i DO_NOT_USE_glTexCoord3i +#undef glTexCoord3iv +#define glTexCoord3iv DO_NOT_USE_glTexCoord3iv +#undef glTexCoord3s +#define glTexCoord3s DO_NOT_USE_glTexCoord3s +#undef glTexCoord3sv +#define glTexCoord3sv DO_NOT_USE_glTexCoord3sv +#undef glTexCoord4d +#define glTexCoord4d DO_NOT_USE_glTexCoord4d +#undef glTexCoord4dv +#define glTexCoord4dv DO_NOT_USE_glTexCoord4dv +#undef glTexCoord4f +#define glTexCoord4f DO_NOT_USE_glTexCoord4f +#undef glTexCoord4fv +#define glTexCoord4fv DO_NOT_USE_glTexCoord4fv +#undef glTexCoord4i +#define glTexCoord4i DO_NOT_USE_glTexCoord4i +#undef glTexCoord4iv +#define glTexCoord4iv DO_NOT_USE_glTexCoord4iv +#undef glTexCoord4s +#define glTexCoord4s DO_NOT_USE_glTexCoord4s +#undef glTexCoord4sv +#define glTexCoord4sv DO_NOT_USE_glTexCoord4sv + +#undef glVertex2d +#define glVertex2d DO_NOT_USE_glVertex2d +#undef glVertex2dv +#define glVertex2dv DO_NOT_USE_glVertex2dv +#undef glVertex2f +#define glVertex2f DO_NOT_USE_glVertex2f +#undef glVertex2fv +#define glVertex2fv DO_NOT_USE_glVertex2fv +#undef glVertex2i +#define glVertex2i DO_NOT_USE_glVertex2i +#undef glVertex2iv +#define glVertex2iv DO_NOT_USE_glVertex2iv +#undef glVertex2s +#define glVertex2s DO_NOT_USE_glVertex2s +#undef glVertex2sv +#define glVertex2sv DO_NOT_USE_glVertex2sv +#undef glVertex3d +#define glVertex3d DO_NOT_USE_glVertex3d +#undef glVertex3dv +#define glVertex3dv DO_NOT_USE_glVertex3dv +#undef glVertex3f +#define glVertex3f DO_NOT_USE_glVertex3f +#undef glVertex3fv +#define glVertex3fv DO_NOT_USE_glVertex3fv +#undef glVertex3i +#define glVertex3i DO_NOT_USE_glVertex3i +#undef glVertex3iv +#define glVertex3iv DO_NOT_USE_glVertex3iv +#undef glVertex3s +#define glVertex3s DO_NOT_USE_glVertex3s +#undef glVertex3sv +#define glVertex3sv DO_NOT_USE_glVertex3sv +#undef glVertex4d +#define glVertex4d DO_NOT_USE_glVertex4d +#undef glVertex4dv +#define glVertex4dv DO_NOT_USE_glVertex4dv +#undef glVertex4f +#define glVertex4f DO_NOT_USE_glVertex4f +#undef glVertex4fv +#define glVertex4fv DO_NOT_USE_glVertex4fv +#undef glVertex4i +#define glVertex4i DO_NOT_USE_glVertex4i +#undef glVertex4iv +#define glVertex4iv DO_NOT_USE_glVertex4iv +#undef glVertex4s +#define glVertex4s DO_NOT_USE_glVertex4s +#undef glVertex4sv +#define glVertex4sv DO_NOT_USE_glVertex4sv + +#undef glMultiTexCoord1d +#define glMultiTexCoord1d DO_NOT_USE_glMultiTexCoord1d +#undef glMultiTexCoord1dv +#define glMultiTexCoord1dv DO_NOT_USE_glMultiTexCoord1dv +#undef glMultiTexCoord1f +#define glMultiTexCoord1f DO_NOT_USE_glMultiTexCoord1f +#undef glMultiTexCoord1fv +#define glMultiTexCoord1fv DO_NOT_USE_glMultiTexCoord1fv +#undef glMultiTexCoord1i +#define glMultiTexCoord1i DO_NOT_USE_glMultiTexCoord1i +#undef glMultiTexCoord1iv +#define glMultiTexCoord1iv DO_NOT_USE_glMultiTexCoord1iv +#undef glMultiTexCoord1s +#define glMultiTexCoord1s DO_NOT_USE_glMultiTexCoord1s +#undef glMultiTexCoord1sv +#define glMultiTexCoord1sv DO_NOT_USE_glMultiTexCoord1sv +#undef glMultiTexCoord2d +#define glMultiTexCoord2d DO_NOT_USE_glMultiTexCoord2d +#undef glMultiTexCoord2dv +#define glMultiTexCoord2dv DO_NOT_USE_glMultiTexCoord2dv +#undef glMultiTexCoord2f +#define glMultiTexCoord2f DO_NOT_USE_glMultiTexCoord2f +#undef glMultiTexCoord2fv +#define glMultiTexCoord2fv DO_NOT_USE_glMultiTexCoord2fv +#undef glMultiTexCoord2i +#define glMultiTexCoord2i DO_NOT_USE_glMultiTexCoord2i +#undef glMultiTexCoord2iv +#define glMultiTexCoord2iv DO_NOT_USE_glMultiTexCoord2iv +#undef glMultiTexCoord2s +#define glMultiTexCoord2s DO_NOT_USE_glMultiTexCoord2s +#undef glMultiTexCoord2sv +#define glMultiTexCoord2sv DO_NOT_USE_glMultiTexCoord2sv +#undef glMultiTexCoord3d +#define glMultiTexCoord3d DO_NOT_USE_glMultiTexCoord3d +#undef glMultiTexCoord3dv +#define glMultiTexCoord3dv DO_NOT_USE_glMultiTexCoord3dv +#undef glMultiTexCoord3f +#define glMultiTexCoord3f DO_NOT_USE_glMultiTexCoord3f +#undef glMultiTexCoord3fv +#define glMultiTexCoord3fv DO_NOT_USE_glMultiTexCoord3fv +#undef glMultiTexCoord3i +#define glMultiTexCoord3i DO_NOT_USE_glMultiTexCoord3i +#undef glMultiTexCoord3iv +#define glMultiTexCoord3iv DO_NOT_USE_glMultiTexCoord3iv +#undef glMultiTexCoord3s +#define glMultiTexCoord3s DO_NOT_USE_glMultiTexCoord3s +#undef glMultiTexCoord3sv +#define glMultiTexCoord3sv DO_NOT_USE_glMultiTexCoord3sv +#undef glMultiTexCoord4d +#define glMultiTexCoord4d DO_NOT_USE_glMultiTexCoord4d +#undef glMultiTexCoord4dv +#define glMultiTexCoord4dv DO_NOT_USE_glMultiTexCoord4dv +#undef glMultiTexCoord4f +#define glMultiTexCoord4f DO_NOT_USE_glMultiTexCoord4f +#undef glMultiTexCoord4fv +#define glMultiTexCoord4fv DO_NOT_USE_glMultiTexCoord4fv +#undef glMultiTexCoord4i +#define glMultiTexCoord4i DO_NOT_USE_glMultiTexCoord4i +#undef glMultiTexCoord4iv +#define glMultiTexCoord4iv DO_NOT_USE_glMultiTexCoord4iv +#undef glMultiTexCoord4s +#define glMultiTexCoord4s DO_NOT_USE_glMultiTexCoord4s +#undef glMultiTexcoord4sv +#define glMultiTexcoord4sv DO_NOT_USE_glMultiTexCoord4sv + +#undef glMultiTexCoord1dARB +#define glMultiTexCoord1dARB DO_NOT_USE_glMultiTexCoord1dARB +#undef glMultiTexCoord1dvARB +#define glMultiTexCoord1dvARB DO_NOT_USE_glMultiTexCoord1dvARB +#undef glMultiTexCoord1fARB +#define glMultiTexCoord1fARB DO_NOT_USE_glMultiTexCoord1fARB +#undef glMultiTexCoord1fvARB +#define glMultiTexCoord1fvARB DO_NOT_USE_glMultiTexCoord1fvARB +#undef glMultiTexCoord1iARB +#define glMultiTexCoord1iARB DO_NOT_USE_glMultiTexCoord1iARB +#undef glMultiTexCoord1ivARB +#define glMultiTexCoord1ivARB DO_NOT_USE_glMultiTexCoord1ivARB +#undef glMultiTexCoord1sARB +#define glMultiTexCoord1sARB DO_NOT_USE_glMultiTexCoord1sARB +#undef glMultiTexCoord1svARB +#define glMultiTexCoord1svARB DO_NOT_USE_glMultiTexCoord1svARB +#undef glMultiTexCoord2dARB +#define glMultiTexCoord2dARB DO_NOT_USE_glMultiTexCoord2dARB +#undef glMultiTexCoord2dvARB +#define glMultiTexCoord2dvARB DO_NOT_USE_glMultiTexCoord2dvARB +#undef glMultiTexCoord2fARB +#define glMultiTexCoord2fARB DO_NOT_USE_glMultiTexCoord2fARB +#undef glMultiTexCoord2fvARB +#define glMultiTexCoord2fvARB DO_NOT_USE_glMultiTexCoord2fvARB +#undef glMultiTexCoord2iARB +#define glMultiTexCoord2iARB DO_NOT_USE_glMultiTexCoord2iARB +#undef glMultiTexCoord2ivARB +#define glMultiTexCoord2ivARB DO_NOT_USE_glMultiTexCoord2ivARB +#undef glMultiTexCoord2sARB +#define glMultiTexCoord2sARB DO_NOT_USE_glMultiTexCoord2sARB +#undef glMultiTexCoord2svARB +#define glMultiTexCoord2svARB DO_NOT_USE_glMultiTexCoord2svARB +#undef glMultiTexCoord3dARB +#define glMultiTexCoord3dARB DO_NOT_USE_glMultiTexCoord3dARB +#undef glMultiTexCoord3dvARB +#define glMultiTexCoord3dvARB DO_NOT_USE_glMultiTexCoord3dvARB +#undef glMultiTexCoord3fARB +#define glMultiTexCoord3fARB DO_NOT_USE_glMultiTexCoord3fARB +#undef glMultiTexCoord3fvARB +#define glMultiTexCoord3fvARB DO_NOT_USE_glMultiTexCoord3fvARB +#undef glMultiTexCoord3iARB +#define glMultiTexCoord3iARB DO_NOT_USE_glMultiTexCoord3iARB +#undef glMultiTexCoord3ivARB +#define glMultiTexCoord3ivARB DO_NOT_USE_glMultiTexCoord3ivARB +#undef glMultiTexCoord3sARB +#define glMultiTexCoord3sARB DO_NOT_USE_glMultiTexCoord3sARB +#undef glMultiTexCoord3svARB +#define glMultiTexCoord3svARB DO_NOT_USE_glMultiTexCoord3svARB +#undef glMultiTexCoord4dARB +#define glMultiTexCoord4dARB DO_NOT_USE_glMultiTexCoord4dARB +#undef glMultiTexCoord4dvARB +#define glMultiTexCoord4dvARB DO_NOT_USE_glMultiTexCoord4dvARB +#undef glMultiTexCoord4fARB +#define glMultiTexCoord4fARB DO_NOT_USE_glMultiTexCoord4fARB +#undef glMultiTexCoord4fvARB +#define glMultiTexCoord4fvARB DO_NOT_USE_glMultiTexCoord4fvARB +#undef glMultiTexCoord4iARB +#define glMultiTexCoord4iARB DO_NOT_USE_glMultiTexCoord4iARB +#undef glMultiTexCoord4ivARB +#define glMultiTexCoord4ivARB DO_NOT_USE_glMultiTexCoord4ivARB +#undef glMultiTexCoord4sARB +#define glMultiTexCoord4sARB DO_NOT_USE_glMultiTexCoord4sARB +#undef glMultiTexcoord4svARB +#define glMultiTexcoord4svARB DO_NOT_USE_glMultiTexCoord4svARB + +#undef glFogCoordd +#define glFogCoordd DO_NOT_USE_glFogCoordd +#undef glFogCoorddv +#define glFogCoorddv DO_NOT_USE_glFogCoorddv +#undef glFogCoordf +#define glFogCoordf DO_NOT_USE_glFogCoordf +#undef glFogCoordfv +#define glFogCoordfv DO_NOT_USE_glFogCoordfv + +#undef glSecondaryColor3b +#define glSecondaryColor3b DO_NOT_USE_glSecondaryColor3b +#undef glSecondaryColor3bv +#define glSecondaryColor3bv DO_NOT_USE_glSecondaryColor3bv +#undef glSecondaryColor3d +#define glSecondaryColor3d DO_NOT_USE_glSecondaryColor3d +#undef glSecondaryColor3dv +#define glSecondaryColor3dv DO_NOT_USE_glSecondaryColor3dv +#undef glSecondaryColor3f +#define glSecondaryColor3f DO_NOT_USE_glSecondaryColor3f +#undef glSecondaryColor3fv +#define glSecondaryColor3fv DO_NOT_USE_glSecondaryColor3fv +#undef glSecondaryColor3i +#define glSecondaryColor3i DO_NOT_USE_glSecondaryColor3i +#undef glSecondaryColor3iv +#define glSecondaryColor3iv DO_NOT_USE_glSecondaryColor3iv +#undef glSecondaryColor3s +#define glSecondaryColor3s DO_NOT_USE_glSecondaryColor3s +#undef glSecondaryColor3sv +#define glSecondaryColor3sv DO_NOT_USE_glSecondaryColor3sv +#undef glSecondaryColor3ub +#define glSecondaryColor3ub DO_NOT_USE_glSecondaryColor3ub +#undef glSecondaryColor3ubv +#define glSecondaryColor3ubv DO_NOT_USE_glSecondaryColor3ubv +#undef glSecondaryColor3ui +#define glSecondaryColor3ui DO_NOT_USE_glSecondaryColor3ui +#undef glSecondaryColor3uiv +#define glSecondaryColor3uiv DO_NOT_USE_glSecondaryColor3uiv +#undef glSecondaryColor3us +#define glSecondaryColor3us DO_NOT_USE_glSecondaryColor3us +#undef glSecondaryColor3usv +#define glSecondaryColor3usv DO_NOT_USE_glSecondaryColor3usv + +// Lighting + +#undef glColorMaterial +#define glColorMaterial DO_NOT_USE_glColorMaterial + +#undef glMaterialf +#define glMaterialf DO_NOT_USE_glMaterialf +#undef glMaterialfv +#define glMaterialfv DO_NOT_USE_glMaterialfv +#undef glMateriali +#define glMateriali DO_NOT_USE_glMateriali +#undef glMaterialiv +#define glMaterialiv DO_NOT_USE_glMaterialiv + +#undef glGetMaterialfv +#define glGetMaterialfv DO_NOT_USE_glGetMaterialfv +#undef glGetMaterialiv +#define glGetMaterialiv DO_NOT_USE_glGetMaterialiv + +#undef glLightf +#define glLightf DO_NOT_USE_glLightf +#undef glLightfv +#define glLightfv DO_NOT_USE_glLightfv +#undef glLighti +#define glLighti DO_NOT_USE_glLighti +#undef glLightiv +#define glLightiv DO_NOT_USE_glLightiv + +#undef glLightModelf +#define glLightModelf DO_NOT_USE_glLightModelf +#undef glLightModeli +#define glLightModeli DO_NOT_USE_glLightModeli +#undef glLightModelfv +#define glLightModelfv DO_NOT_USE_glLightModelfv +#undef glLightModeliv +#define glLightModeliv DO_NOT_USE_glLightModeliv + +#undef GL_LIGHT0 +#define GL_LIGHT0 DO_NOT_USE_GL_LIGHT0 +#undef GL_LIGHT1 +#define GL_LIGHT1 DO_NOT_USE_GL_LIGHT1 +#undef GL_LIGHT2 +#define GL_LIGHT2 DO_NOT_USE_GL_LIGHT2 +#undef GL_LIGHT3 +#define GL_LIGHT3 DO_NOT_USE_GL_LIGHT3 +#undef GL_LIGHT4 +#define GL_LIGHT4 DO_NOT_USE_GL_LIGHT4 +#undef GL_LIGHT5 +#define GL_LIGHT5 DO_NOT_USE_GL_LIGHT5 +#undef GL_LIGHT6 +#define GL_LIGHT6 DO_NOT_USE_GL_LIGHT6 +#undef GL_LIGHT7 +#define GL_LIGHT7 DO_NOT_USE_GL_LIGHT7 + +#undef GL_LIGHTING +#define GL_LIGHTING DO_NOT_USE_GL_LIGHTING + +#undef GL_COLOR_MATERIAL +#define GL_COLOR_MATERIAL DO_NOT_USE_GL_COLOR_MATERIAL + +/* display lists */ +//#undef glCallList +//#define glCallList DO_NOT_USE_glCallList +//#undef glEndList +//#define glEndList DO_NOT_USE_glEndList +//#undef glGenLists +//#define glGenLists DO_NOT_USE_glGenLists +//#undef glListBase +//#define glListBase DO_NOT_USE_glListBase +//#undef glNewList +//#define glNewList DO_NOT_USE_glNewList + +/* GLU */ +#undef gluUnProject +#define gluUnProject DO_NOT_USE_gluUnProject + +/* Rectangles */ +#undef glRectf +#define glRectf DO_NOT_USE_glRectf +#undef glRecti +#define glRecti DO_NOT_USE_glRecti + +/* Matrixes */ +//#undef GL_MATRIX_MODE +//#define GL_MATRIX_MODE DO_NOT_USE_GL_MATRIX_MODE +//#undef GL_COLOR_MATRIX +//#define GL_COLOR_MATRIX DO_NOT_USE_GL_COLOR_MATRIX +//#undef GL_MODELVIEW_MATRIX +//#define GL_MODELVIEW_MATRIX DO_NOT_USE_GL_MODELVIEW_MATRIX +//#undef GL_PROJECTION_MATRIX +//#define GL_PROJECTION_MATRIX DO_NOT_USE_GL_PROJECTION_MATRIX +//#undef GL_TEXTURE_MATRIX +//#define GL_TEXTURE_MATRIX DO_NOT_USE_GL_TEXTURE_MATRIX +//#undef GL_COLOR +//#define GL_COLOR DO_NOT_USE_GL_COLOR +//#undef GL_MODELVIEW +//#define GL_MODELVIEW DO_NOT_USE_GL_MODELVIEW +//#undef GL_PROJECTION +//#define GL_PROJECTION DO_NOT_USE_GL_PROJECTION +//#undef GL_TEXTURE +//#define GL_TEXTURE DO_NOT_USE_GL_TEXTURE + +#undef glMatrixMode +#define glMatrixMode DO_NOT_USE_glMatrixMode +#undef glMultMatrixf +#define glMultMatrixf DO_NOT_USE_glMultMatrixf +#undef glMultMatrixd +#define glMultMatrixd DO_NOT_USE_glMultMatrixd +#undef glMultTransposeMatrixf +#define glMultTransposeMatrixf DO_NOT_USE_glMultTransposeMatrixf +#undef glMultTransposeMatrixd +#define glMultTransposeMatrixd DO_NOT_USE_glMultTransposeMatrixd +#undef glLoadMatrixf +#define glLoadMatrixf DO_NOT_USE_glLoadMatrixf +#undef glLoadMatrixd +#define glLoadMatrixd DO_NOT_USE_glLoadMatrixd +#undef glLoadTransposeMatrixf +#define glLoadTransposeMatrixf DO_NOT_USE_glLoadTransposeMatrixf +#undef glLoadTransposeMatrixd +#define glLoadTransposeMatrixd DO_NOT_USE_glLoadTransposeMatrixd +#undef glPopMatrix +#define glPopMatrix DO_NOT_USE_glPopMatrix +#undef glPushMatrix +#define glPushMatrix DO_NOT_USE_glPushMatrix +#undef glTranslatef +#define glTranslatef DO_NOT_USE_glTranslatef +#undef glTranslated +#define glTranslated DO_NOT_USE_glTranslated +#undef glScalef +#define glScalef DO_NOT_USE_glScalef +#undef glScaled +#define glScaled DO_NOT_USE_glScaled +#undef glRotatef +#define glRotatef DO_NOT_USE_glRotatef +#undef glRotated +#define glRotated DO_NOT_USE_glRotated +#undef glOrtho +#define glOrtho DO_NOT_USE_glOrtho +#undef glFrustum +#define glFrustum DO_NOT_USE_glFrustum +#undef glLoadIdentity +#define glLoadItentity DO_NOT_USE_glLoadIdentity + +/* these aren't really deprecated, but the corresponding state query (glGet) is */ +#undef glDepthRange +#define glDepthRange DO_NOT_USE_glDepthRange +#undef glBindTexture +#define glBindTexture DO_NOT_USE_glBindTexture +#undef glDepthMask +#define glDepthMask DO_NOT_USE_glDepthMask +#undef glViewport +#define glViewport DO_NOT_USE_glViewport + +#undef glRenderMode +#define glRenderMode DO_NOT_USE_glRenderMode +#undef glSelectBuffer +#define glSelectBuffer DO_NOT_USE_glSelectBuffer +#undef glInitNames +#define glInitNames DO_NOT_USE_glInitNames +#undef glPopName +#define glPopName DO_NOT_USE_glPopName +#undef glPushName +#define glPushName DO_NOT_USE_glPushName +#undef glLoadName +#define glLoadName DO_NOT_USE_glLoadName + +#undef glClipPlane +#define glClipPlane DO_NOT_USE_glClipPlane + +#undef glPointSize +#define glPointSize DO_NOT_USE_glPointSize + +#undef glLineStipple +#define glLineStipple DO_NOT_USE_glLineStipple +#undef glPolygonStipple +#define glPolygonStipple DO_NOT_USE_glPolygonStipple +#undef glPolygonMode +#define glPolygonMode DO_NOT_USE_glPolygonMode +#undef glLineWidth +#define glLineWidth DO_NOT_USE_glLineWidth +#undef GL_LINE_SMOOTH +#define GL_LINE_SMOOTH DO_NOT_USE_GL_LINE_SMOOTH +#endif + +#endif /* _GPU_DEPRECATED_H_ */ diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 3ddec157c49..a4ac8424fbc 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -29,21 +29,32 @@ * \ingroup gpu */ -#ifndef __GPU_DRAW_H__ -#define __GPU_DRAW_H__ +#ifndef _GPU_DRAW_H_ +#define _GPU_DRAW_H_ + +#include "BLI_sys_types.h" + +#include "GPU_glew.h" + + #ifdef __cplusplus extern "C" { #endif + + +struct MTFace; struct Image; struct ImageUser; -struct MTFace; +struct ImBuf; +struct SmokeModifierData; +struct RegionView3D; struct Object; struct Scene; struct View3D; -struct RegionView3D; -struct SmokeModifierData; + + /* OpenGL drawing functions related to shading. These are also * shared with the game engine, where there were previously @@ -120,6 +131,8 @@ float GPU_get_anisotropic(void); /* enable gpu mipmapping */ void GPU_set_gpu_mipmapping(int gpu_mipmap); +GLenum GPU_mipmap_2D(GLboolean genmip, GLenum internalFormat, int w, int h, GLenum type, void* data); + /* Image updates and free * - these deal with images bound as opengl textures */ @@ -148,4 +161,3 @@ void GPU_free_unused_buffers(void); #endif #endif - diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index 04c4119df6e..3124da21ee3 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -20,17 +20,21 @@ * * The Original Code is: all of this file. * - * Contributor(s): Brecht Van Lommel. + * Contributor(s): Brecht Van Lommel, Jason Wilkins. * * ***** END GPL LICENSE BLOCK ***** */ -/** \file GPU_extensions.h +/** \file source/blender/gpu/GPU_extensions.h * \ingroup gpu */ -#ifndef __GPU_EXTENSIONS_H__ -#define __GPU_EXTENSIONS_H__ +#ifndef _GPU_EXTENSIONS_H_ +#define _GPU_EXTENSIONS_H_ + +#include "BLI_sys_types.h" + +#include <stddef.h> #ifdef __cplusplus extern "C" { @@ -39,7 +43,7 @@ extern "C" { struct Image; struct ImageUser; struct PreviewImage; - + struct GPUTexture; typedef struct GPUTexture GPUTexture; @@ -55,9 +59,7 @@ typedef struct GPUShader GPUShader; /* GPU extensions support */ void GPU_extensions_disable(void); -void GPU_extensions_init(void); /* call this before running any of the functions below */ -void GPU_extensions_exit(void); -int GPU_print_error(const char *str); +bool GPU_print_error(const char *str); int GPU_glsl_support(void); int GPU_non_power_of_two_support(void); @@ -101,7 +103,7 @@ int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver); * graphics card capabilities the texture may actually be stored in a * larger texture with power of two dimensions. the actual dimensions * may be queried with GPU_texture_opengl_width/height. GPU_texture_coord_2f - * calls glTexCoord2f with the coordinates adjusted for this. + * calls TexCoord2f with the coordinates adjusted for this. * - can use reference counting: * - reference counter after GPU_texture_create is 1 * - GPU_texture_ref increases by one @@ -133,7 +135,9 @@ 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); -int GPU_texture_opengl_bindcode(GPUTexture *tex); +int GPU_texture_opengl_bindcode(const GPUTexture *tex); + +unsigned char *GPU_texture_dup_pixels(const GPUTexture *tex, size_t *count_out); /* GPU Framebuffer * - this is a wrapper for an OpenGL framebuffer object (FBO). in practice @@ -143,7 +147,7 @@ int GPU_texture_opengl_bindcode(GPUTexture *tex); * be called before rendering to the window framebuffer again */ GPUFrameBuffer *GPU_framebuffer_create(void); -int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]); +bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]); void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex); void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex, int w, int h); void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex); @@ -168,7 +172,8 @@ int GPU_offscreen_height(GPUOffScreen *ofs); * - 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, const char *libcode, const char *defines); +GPUShader *GPU_shader_create(const char* nickname, const char *vertexcode, const char *fragcode, const char *libcode, const char *defines); + void GPU_shader_free(GPUShader *shader); void GPU_shader_bind(GPUShader *shader); @@ -207,6 +212,8 @@ typedef struct GPUVertexAttribs { int totlayer; } GPUVertexAttribs; +int GPU_max_textures(void); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/GPU_font.h b/source/blender/gpu/GPU_font.h new file mode 100644 index 00000000000..e0095d54f04 --- /dev/null +++ b/source/blender/gpu/GPU_font.h @@ -0,0 +1,56 @@ +#ifndef _GPU_FONT_H_ +#define _GPU_FONT_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_font.h + * \ingroup gpu + */ + + + +#ifdef __cplusplus +extern "C" { +#endif + + +void GPU_font_begin(void); +void GPU_font_end (void); + +void GPU_font_shader_init (void); +void GPU_font_shader_exit (void); +void GPU_font_shader_bind (void); +void GPU_font_shader_unbind(void); + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/blender/gpu/GPU_glew.h b/source/blender/gpu/GPU_glew.h new file mode 100644 index 00000000000..88263808abe --- /dev/null +++ b/source/blender/gpu/GPU_glew.h @@ -0,0 +1,340 @@ +#ifndef _GPU_GLEW_H_ +#define _GPU_GLEW_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_glew.h + * \ingroup gpu + */ + +#include "glew-mx.h" + + + +#ifndef GPU_MANGLE_DEPRECATED +#define GPU_MANGLE_DEPRECATED 1 +#endif + +#if GPU_MANGLE_DEPRECATED +#include "GPU_deprecated.h" +#endif + + + + +/* +The following section is for any simple stuff that is missing from GLEW when +compiled with either the GLEW_ES_ONLY or the GLEW_NO_ES flag. + +Should limit this to simple things. +More complex version shims should be placed elsewhere. + +Also, only put in stuff as it is needed. +*/ + + + +#if defined(GLEW_ES_ONLY) + + + +/* ES does not support the GLdouble type. */ +#ifndef GLdouble +#define GLdouble double +#endif + + + +/* +Need stubs for these version checks if compiling with only ES support. +Rely on compiler to eliminate unreachable code when version checks become constants. +*/ + +#ifndef GLEW_VERSION_1_1 +#define GLEW_VERSION_1_1 0 +#endif + +#ifndef GLEW_VERSION_1_2 +#define GLEW_VERSION_1_2 0 +#endif + +#ifndef GLEW_VERSION_1_3 +#define GLEW_VERSION_1_3 0 +#endif + +#ifndef GLEW_VERSION_1_4 +#define GLEW_VERSION_1_4 0 +#endif + +#ifndef GLEW_VERSION_1_5 +#define GLEW_VERSION_1_5 0 +#endif + +#ifndef GLEW_VERSION_2_0 +#define GLEW_VERSION_2_0 0 +#endif + +#ifndef GLEW_VERSION_3_0 +#define GLEW_VERSION_3_0 0 +#endif + +#ifndef GLEW_ARB_shader_objects +#define GLEW_ARB_shader_objects 0 +#endif + +#ifndef GLEW_ARB_vertex_shader +#define GLEW_ARB_vertex_shader 0 +#endif + +#ifndef GLEW_ARB_vertex_program +#define GLEW_ARB_vertex_program 0 +#endif + +#ifndef GLEW_ARB_fragment_program +#define GLEW_ARB_fragment_program 0 +#endif + +#ifndef GLEW_ARB_vertex_buffer_object +#define GLEW_ARB_vertex_buffer_object 0 +#endif + +#ifndef GLEW_ARB_framebuffer_object +#define GLEW_ARB_framebuffer_object 0 +#endif + +#ifndef GLEW_ARB_multitexture +#define GLEW_ARB_multitexture 0 +#endif + +#ifndef GLEW_EXT_framebuffer_object +#define GLEW_EXT_framebuffer_object 0 +#endif + +#ifndef GLEW_ARB_depth_texture +#define GLEW_ARB_depth_texture 0 +#endif + +#ifndef GLEW_ARB_shadow +#define GLEW_ARB_shadow 0 +#endif + +#ifndef GLEW_ARB_texture_float +#define GLEW_ARB_texture_float 0 +#endif + +#ifndef GLEW_ARB_texture_non_power_of_two +#define GLEW_ARB_texture_non_power_of_two 0 +#endif + +#ifndef GLEW_ARB_texture3D +#define GLEW_ARB_texture3D 0 +#endif + +#ifndef GLEW_EXT_texture3D +#define GLEW_EXT_texture3D 0 +#endif + +#ifndef GLEW_ARB_texture_rg +#define GLEW_ARB_texture_rg 0 +#endif + +#ifndef GLEW_ARB_texture_query_lod +#define GLEW_ARB_texture_query_lod 0 +#endif + + + +/* +The following symbolic constants are missing from an ES only header, +so alias them to their (same valued) extension versions which are available in the header. + +Be careful that this does not lead to unguarded use of what are extensions in ES! + +Some of these may be here simply to patch inconsistencies in the header files. +*/ + +// XXX jwilkins: need to check ALL of these to make sure you didn't cover an unguarded use of an extension/version + +#ifndef GL_TEXTURE_3D +#define GL_TEXTURE_3D GL_TEXTURE_3D_OES +#endif + +#ifndef glTexImage3D +#define glTexImage3D glTexImage3DOES +#endif + +#ifndef glTexSubImage3D +#define glTexSubImage3D glTexSubImage3DOES +#endif + +#ifndef GL_TEXTURE_WRAP_R +#define GL_TEXTURE_WRAP_R GL_TEXTURE_WRAP_R_OES +#endif + +#ifndef GL_TEXTURE_COMPARE_MODE +#define GL_TEXTURE_COMPARE_MODE GL_TEXTURE_COMPARE_MODE_EXT +#endif + +#ifndef GL_COMPARE_REF_TO_TEXTURE +#define GL_COMPARE_REF_TO_TEXTURE GL_COMPARE_REF_TO_TEXTURE_EXT +#endif + +#ifndef GL_TEXTURE_COMPARE_FUNC +#define GL_TEXTURE_COMPARE_FUNC GL_TEXTURE_COMPARE_FUNC_EXT +#endif + +#ifndef GL_RGBA8 +#define GL_RGBA8 GL_RGBA8_OES +#endif + +#ifndef GL_RGBA16F +#define GL_RGBA16F GL_RGBA16F_EXT +#endif + +#ifndef GL_RG32F +#define GL_RG32F GL_RG32F_EXT +#endif + +#ifndef GL_RGB8 +#define GL_RGB8 GL_RGB8_OES +#endif + +#ifndef GL_RG +#define GL_RG GL_RG_EXT +#endif + +#ifndef GL_RED +#define GL_RED GL_RED_EXT +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_OES +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_OES +#endif + +#ifndef GL_WRITE_ONLY +#define GL_WRITE_ONLY GL_WRITE_ONLY_OES +#endif + +#ifndef GLEW_ARB_vertex_array_object +#define GLEW_ARB_vertex_array_object 0 +#endif + + + +/* end of defined(GLEW_ES_ONLY) */ +#elif defined(GLEW_NO_ES) + + + +/* +Need stubs for these version checks if compiling without any support. +Rely on compiler to eliminate unreachable code when version checks become constants +*/ + +#ifndef GLEW_ES_VERSION_2_0 +#define GLEW_ES_VERSION_2_0 0 +#endif + +#ifndef GLEW_EXT_texture_storage +#define GLEW_EXT_texture_storage 0 +#endif + +#ifndef GLEW_OES_framebuffer_object +#define GLEW_OES_framebuffer_object 0 +#endif + +#ifndef GLEW_OES_mapbuffer +#define GLEW_OES_mapbuffer 0 +#endif + +#ifndef GLEW_OES_required_internalformat +#define GLEW_OES_required_internalformat 0 +#endif + +#ifndef GLEW_EXT_color_buffer_half_float +#define GLEW_EXT_color_buffer_half_float 0 +#endif + +#ifndef GLEW_OES_depth_texture +#define GLEW_OES_depth_texture 0 +#endif + +#ifndef GLEW_EXT_shadow_samplers +#define GLEW_EXT_shadow_samplers 0 +#endif + +#ifndef GLEW_ARB_texture3D +#define GLEW_ARB_texture3D 0 +#endif + +#ifndef GLEW_OES_texture_3D +#define GLEW_OES_texture_3D 0 +#endif + +#ifndef GLEW_EXT_texture_rg +#define GLEW_EXT_texture_rg 0 +#endif + +#ifndef GLEW_OES_vertex_array_object +#define GLEW_OES_vertex_array_object 0 +#endif + + + +/* +The following symbolic constants are missing when there is no ES support, +so alias them to their (same valued) extension versions which are available in the header. + +Desktop GL typically does not have any extensions that originated from ES, +unlike ES which has many extensions to replace what was taken out. + +For that reason these aliases are more likely just patching inconsistencies in the header files. +*/ + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT +#endif + +#endif /* defined(GLEW_NO_ES) */ + + + + +#endif /* _GPU_GLEW_H_ */ diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h new file mode 100644 index 00000000000..dcb64628f24 --- /dev/null +++ b/source/blender/gpu/GPU_immediate.h @@ -0,0 +1,965 @@ +#ifndef _GPU_IMMEDIATE_INLINE_H_ +#define _GPU_IMMEDIATE_INLINE_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_immediate.h + * \ingroup gpu + */ + +#include "GPU_common.h" +#include "GPU_glew.h" +#include "GPU_safety.h" + +/* external */ + +#include "BLI_math_base.h" +#include "BLI_utildefines.h" + +#include "GPU_safety.h" + +/* standard */ +#include <limits.h> +#include <string.h> /* for size_t */ + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +struct GPUimmediate; +struct GPUindex; + + + +void gpu_lock_buffer_gl(void); +void gpu_unlock_buffer_gl(void); +void gpu_begin_buffer_gl(void); +void gpu_end_buffer_gl(void); +void gpu_shutdown_buffer_gl(struct GPUimmediate *__restrict immediate); +void gpu_current_normal_gl(void); +void gpu_index_begin_buffer_gl(void); +void gpu_index_end_buffer_gl(void); +void gpu_index_shutdown_buffer_gl(struct GPUindex *__restrict index); +void gpu_draw_elements_gl(void); +void gpu_draw_range_elements_gl(void); + + + +#if GPU_SAFETY + +/* Define some useful, but potentially slow, checks for correct API usage. */ + +#define GPU_CHECK_BASE(var) \ + GPU_CHECK_NO_ERROR(); \ + GPU_SAFE_RETURN(GPU_IMMEDIATE != NULL, var,); + +#define GPU_CHECK_NO_BEGIN(var) \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->mappedBuffer == NULL, var,); + +#define GPU_CHECK_IS_LOCKED(var) \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount > 0, var,); + +#define GPU_CHECK_NO_LOCK(var) \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount == 0, var,); + +/* Each block contains variables that can be inspected by a + debugger in the event that an assert is triggered. */ + +#define GPU_CHECK_CAN_BEGIN() \ + { \ + GLboolean immediateOK; \ + GLboolean isLockedOK; \ + GLboolean noBeginOK; \ + GPU_CHECK_BASE(immediateOK); \ + GPU_CHECK_IS_LOCKED(isLockedOK) \ + GPU_CHECK_NO_BEGIN(noBeginOK) \ + } + +#define GPU_CHECK_CAN_END() \ + { \ + GLboolean immediateOK; \ + GLboolean isLockedOK; \ + GLboolean hasBegunOK; \ + GPU_CHECK_BASE(immediateOK); \ + GPU_CHECK_IS_LOCKED(isLockedOK) \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->mappedBuffer != NULL, hasBegunOK,); \ + } + +#define GPU_CHECK_MODE(_mode) \ + { \ + GLboolean immediateOK; \ + GLboolean isModeOK; \ + GPU_CHECK_BASE(immediateOK); \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->mode == (_mode), isModeOK,); \ + } + +#define GPU_CHECK_CAN_REPEAT() GPU_CHECK_CAN_BEGIN() + +#else + +#define GPU_CHECK_CAN_BEGIN() +#define GPU_CHECK_CAN_END() +#define GPU_CHECK_MODE(mode) +#define GPU_CHECK_CAN_REPEAT() + +#endif + + + +void gpuImmediateElementSizes( + GLint vertexSize, + GLint normalSize, + GLint colorSize); + +void gpuImmediateMaxVertexCount(GLsizei maxVertexCount); + +void gpuImmediateSamplerCount(size_t count); +void gpuImmediateSamplerMap(const GLint *__restrict map); + +void gpuImmediateTexCoordCount(size_t count); +void gpuImmediateTexCoordSizes(const GLint *__restrict sizes); + +void gpuImmediateFloatAttribCount(size_t count); +void gpuImmediateFloatAttribSizes(const GLint *__restrict sizes); +void gpuImmediateFloatAttribIndexMap(const GLuint *__restrict map); + +void gpuImmediateUbyteAttribCount(size_t count); +void gpuImmediateUbyteAttribSizes(const GLint *__restrict sizes); +void gpuImmediateUbyteAttribIndexMap(const GLuint *__restrict map); + +void gpuImmediateFormatReset(void); +void gpuImmediateLock(void); +void gpuImmediateUnlock(void); +GLint gpuImmediateLockCount(void); + +void gpuBegin(GLenum mode); +void gpuEnd(void); + + +typedef struct GPUarrays { + GLenum colorType; + GLint colorSize; + GLint colorStride; + const void *__restrict colorPointer; + + GLenum normalType; + GLint normalStride; + const void *__restrict normalPointer; + + GLenum vertexType; + GLint vertexSize; + GLint vertexStride; + const void *__restrict vertexPointer; +} GPUarrays; + +#define GPU_MAX_FLOAT_ATTRIBS 32 +#define GPU_MAX_UBYTE_ATTRIBS 32 + +typedef struct GPUimmediateformat { + GLint vertexSize; + GLint normalSize; + GLint colorSize; + GLint texCoordSize [GPU_MAX_COMMON_TEXCOORDS]; + GLint attribSize_f [GPU_MAX_FLOAT_ATTRIBS]; + GLint attribSize_ub[GPU_MAX_UBYTE_ATTRIBS]; + + size_t texCoordCount; + + GLint samplerMap[GPU_MAX_COMMON_SAMPLERS]; + size_t samplerCount; + + GLuint attribIndexMap_f [GPU_MAX_FLOAT_ATTRIBS]; + GLboolean attribNormalized_f[GPU_MAX_FLOAT_ATTRIBS]; + size_t attribCount_f; + + GLuint attribIndexMap_ub [GPU_MAX_UBYTE_ATTRIBS]; + GLboolean attribNormalized_ub[GPU_MAX_UBYTE_ATTRIBS]; + size_t attribCount_ub; +} GPUimmediateformat; + +typedef struct GPUimmediate { + GLenum mode; + + GPUimmediateformat format; + + GLfloat vertex[4]; + GLfloat normal[3]; + GLfloat texCoord[GPU_MAX_COMMON_TEXCOORDS][4]; + GLubyte color[4]; + GLfloat attrib_f[GPU_MAX_FLOAT_ATTRIBS][4]; + GLubyte attrib_ub[GPU_MAX_UBYTE_ATTRIBS][4]; + + GLubyte *__restrict mappedBuffer; + void *__restrict bufferData; + GLsizei stride; + size_t offset; + GLsizei maxVertexCount; + GLsizei lastPrimVertex; + GLsizei count; + + int lockCount; + + struct GPUindex *__restrict index; + + void (*copyVertex)(void); + +#if GPU_SAFETY + GLint lastTexture; + GLboolean hasOverflowed; +#endif + +} GPUimmediate; + +extern GPUimmediate *__restrict GPU_IMMEDIATE; + + + +GPUimmediate* gpuNewImmediate(void); +void gpuImmediateMakeCurrent(GPUimmediate *__restrict immediate); +void gpuDeleteImmediate(GPUimmediate *__restrict immediate); + + + +void gpuPushImmediate(void); +GPUimmediate* gpuPopImmediate(void); +void gpuImmediateSingleDraw(GLenum mode, GPUimmediate *__restrict immediate); +void gpuImmediateSingleRepeat(GPUimmediate *__restrict immediate); + +void gpuImmediateSingleDrawElements(GLenum mode, GPUimmediate *__restrict immediate); +void gpuImmediateSingleRepeatElements(GPUimmediate *__restrict immediate); + +void gpuImmediateSingleDrawRangeElements(GLenum mode, GPUimmediate *__restrict immediate); +void gpuImmediateSingleRepeatRangeElements(GPUimmediate *__restrict immediate); + + + +/* utility functions to setup vertex format and lock */ +#if GPU_SAFETY + +void gpuSafetyImmediateFormat_V2 (const char* file, int line); +void gpuSafetyImmediateFormat_C4_V2 (const char* file, int line); +void gpuSafetyImmediateFormat_T2_V2 (const char* file, int line); +void gpuSafetyImmediateFormat_T2_V3 (const char* file, int line); +void gpuSafetyImmediateFormat_T2_C4_V2 (const char* file, int line); +void gpuSafetyImmediateFormat_V3 (const char* file, int line); +void gpuSafetyImmediateFormat_N3_V3 (const char* file, int line); +void gpuSafetyImmediateFormat_C4_V3 (const char* file, int line); +void gpuSafetyImmediateFormat_C4_N3_V3 (const char* file, int line); +void gpuSafetyImmediateFormat_T2_C4_N3_V3 (const char* file, int line); +void gpuSafetyImmediateFormat_T3_C4_V3 (const char* file, int line); +void gpuSafetyImmediateUnformat (const char* file, int line); + +#define gpuImmediateFormat_V2() gpuSafetyImmediateFormat_V2 (__FILE__, __LINE__) +#define gpuImmediateFormat_C4_V2() gpuSafetyImmediateFormat_C4_V2 (__FILE__, __LINE__) +#define gpuImmediateFormat_T2_V2() gpuSafetyImmediateFormat_T2_V2 (__FILE__, __LINE__) +#define gpuImmediateFormat_T2_V3() gpuSafetyImmediateFormat_T2_V3 (__FILE__, __LINE__) +#define gpuImmediateFormat_T2_C4_V2() gpuSafetyImmediateFormat_T2_C4_V2 (__FILE__, __LINE__) +#define gpuImmediateFormat_V3() gpuSafetyImmediateFormat_V3 (__FILE__, __LINE__) +#define gpuImmediateFormat_N3_V3() gpuSafetyImmediateFormat_N3_V3 (__FILE__, __LINE__) +#define gpuImmediateFormat_C4_V3() gpuSafetyImmediateFormat_C4_V3 (__FILE__, __LINE__) +#define gpuImmediateFormat_C4_N3_V3() gpuSafetyImmediateFormat_C4_N3_V3 (__FILE__, __LINE__) +#define gpuImmediateFormat_T2_C4_N3_V3() gpuSafetyImmediateFormat_T2_C4_N3_V3 (__FILE__, __LINE__) +#define gpuImmediateFormat_T3_C4_V3() gpuSafetyImmediateFormat_T3_C4_V3 (__FILE__, __LINE__) +#define gpuImmediateUnformat() gpuSafetyImmediateUnformat (__FILE__, __LINE__) + +#else + +void gpuImmediateFormat_V2(void); +void gpuImmediateFormat_C4_V2(void); +void gpuImmediateFormat_T2_V2(void); +void gpuImmediateFormat_T2_V3(void); +void gpuImmediateFormat_T2_C4_V2(void); +void gpuImmediateFormat_V3(void); +void gpuImmediateFormat_N3_V3(void); +void gpuImmediateFormat_C4_V3(void); +void gpuImmediateFormat_C4_N3_V3(void); +void gpuImmediateFormat_T2_C4_N3_V3(void); +void gpuImmediateFormat_T3_C4_V3(void); +void gpuImmediateUnformat(void); + +#endif + + + +extern const GPUarrays GPU_ARRAYS_V2F; +extern const GPUarrays GPU_ARRAYS_C4UB_V2F; +extern const GPUarrays GPU_ARRAYS_C4UB_V3F; +extern const GPUarrays GPU_ARRAYS_V3F; +extern const GPUarrays GPU_ARRAYS_C3F_V3F; +extern const GPUarrays GPU_ARRAYS_C4F_V3F; +extern const GPUarrays GPU_ARRAYS_N3F_V3F; +extern const GPUarrays GPU_ARRAYS_C3F_N3F_V3F; + + + +typedef struct GPUindex { + struct GPUimmediate *__restrict immediate; + + void *__restrict bufferData; + void *__restrict mappedBuffer; + GLsizei maxIndexCount; + GLsizei count; + + GLuint indexMin; + GLuint indexMax; + + GLuint restart; + + GLenum type; + GLsizei offset; +} GPUindex; + +GPUindex* gpuNewIndex(void); +void gpuDeleteIndex(GPUindex *__restrict index); + +void gpuImmediateIndex(GPUindex * index); +GPUindex* gpuGetImmediateIndex(void); +void gpuImmediateMaxIndexCount(GLsizei maxIndexCount, GLenum type); +void gpuImmediateIndexRange(GLuint indexMin, GLuint indexMax); +void gpuImmediateIndexComputeRange(void); +void gpuImmediateIndexRestartValue(GLuint restart); + +void gpuIndexBegin(GLenum type); + +void gpuIndexRelativeubv(GLint offset, GLsizei count, const GLubyte *__restrict indexes); +void gpuIndexRelativeusv(GLint offset, GLsizei count, const GLushort *__restrict indexes); +void gpuIndexRelativeuiv(GLint offset, GLsizei count, const GLuint *__restrict indexes); + +void gpuIndexub(GLubyte index); +void gpuIndexus(GLushort index); +void gpuIndexui(GLuint index); + +void gpuIndexRestart(void); + +void gpuIndexEnd(void); + + + +void gpuAppendClientArrays( + const GPUarrays* arrays, + GLint first, + GLsizei count); + +void gpuDrawClientArrays( + GLenum mode, + const GPUarrays *arrays, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_V2F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_V3F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_C3F_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_C4F_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_N3F_V3F( + GLenum mode, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_C3F_N3F_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_C4UB_V2F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + +void gpuSingleClientArrays_C4UB_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count); + + + +void gpuSingleClientElements_V3F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLsizei count, + const GLuint *__restrict index); + +void gpuSingleClientElements_N3F_V3F( + GLenum mode, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLsizei count, + const GLuint *__restrict indexes); + +void gpuSingleClientElements_C4UB_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLsizei count, + const GLuint *__restrict indexes); + + + +void gpuDrawClientRangeElements( + GLenum mode, + const GPUarrays *__restrict arrays, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes); + +void gpuSingleClientRangeElements_V3F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes); + +void gpuSingleClientRangeElements_N3F_V3F( + GLenum mode, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes); + +void gpuSingleClientRangeElements_C4UB_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes); + + + +void gpu_commit_current (void); +void gpu_commit_samplers(void); + + + +#if defined(GLEW_ES_ONLY) + +/* ES 2.0 doesn't define QUADS, but the immediate mode replacement library emulates QUADS */ +/* (GL core has deprecated QUADS, but it should still be in the header) */ + +#ifndef GL_QUADS +#define GL_QUADS 0x0007 +#endif + +#ifndef GL_QUAD_STRIP +#define GL_QUAD_STRIP 0x0008 +#endif + +#ifndef GL_POLYGON +#define GL_POLYGON 0x0009 +#endif + +#endif + + + +BLI_INLINE void gpuColor3f(GLfloat r, GLfloat g, GLfloat b) +{ + GPU_IMMEDIATE->color[0] = (GLubyte)(255.0f * r); + GPU_IMMEDIATE->color[1] = (GLubyte)(255.0f * g); + GPU_IMMEDIATE->color[2] = (GLubyte)(255.0f * b); + GPU_IMMEDIATE->color[3] = 255; +} + +BLI_INLINE void gpuColor3fv(const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->color[0] = (GLubyte)(255.0f * v[0]); + GPU_IMMEDIATE->color[1] = (GLubyte)(255.0f * v[1]); + GPU_IMMEDIATE->color[2] = (GLubyte)(255.0f * v[2]); + GPU_IMMEDIATE->color[3] = 255; +} + +BLI_INLINE void gpuColor3ub(GLubyte r, GLubyte g, GLubyte b) +{ + GPU_IMMEDIATE->color[0] = r; + GPU_IMMEDIATE->color[1] = g; + GPU_IMMEDIATE->color[2] = b; + GPU_IMMEDIATE->color[3] = 255; +} + +BLI_INLINE void gpuColor3ubv(const GLubyte *__restrict v) +{ + GPU_IMMEDIATE->color[0] = v[0]; + GPU_IMMEDIATE->color[1] = v[1]; + GPU_IMMEDIATE->color[2] = v[2]; + GPU_IMMEDIATE->color[3] = 255; +} + +BLI_INLINE void gpuColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) +{ + GPU_IMMEDIATE->color[0] = (GLubyte)(255.0f * r); + GPU_IMMEDIATE->color[1] = (GLubyte)(255.0f * g); + GPU_IMMEDIATE->color[2] = (GLubyte)(255.0f * b); + GPU_IMMEDIATE->color[3] = (GLubyte)(255.0f * a); +} + +BLI_INLINE void gpuColor4fv(const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->color[0] = (GLubyte)(255.0f * v[0]); + GPU_IMMEDIATE->color[1] = (GLubyte)(255.0f * v[1]); + GPU_IMMEDIATE->color[2] = (GLubyte)(255.0f * v[2]); + GPU_IMMEDIATE->color[3] = (GLubyte)(255.0f * v[3]); +} + +BLI_INLINE void gpuColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) +{ + GPU_IMMEDIATE->color[0] = r; + GPU_IMMEDIATE->color[1] = g; + GPU_IMMEDIATE->color[2] = b; + GPU_IMMEDIATE->color[3] = a; +} + +BLI_INLINE void gpuColor4ubv(const GLubyte *__restrict v) +{ + GPU_IMMEDIATE->color[0] = v[0]; + GPU_IMMEDIATE->color[1] = v[1]; + GPU_IMMEDIATE->color[2] = v[2]; + GPU_IMMEDIATE->color[3] = v[3]; +} + +BLI_INLINE void gpuColor4d(GLdouble r, GLdouble g, GLdouble b, GLdouble a) +{ + GPU_IMMEDIATE->color[0] = (GLubyte)(255.0 * r); + GPU_IMMEDIATE->color[1] = (GLubyte)(255.0 * g); + GPU_IMMEDIATE->color[2] = (GLubyte)(255.0 * b); + GPU_IMMEDIATE->color[3] = (GLubyte)(255.0 * a); +} + + + +/* This function converts a numerical value to the equivalent 24-bit + color, while not being endian-sensitive. On little-endians, this + is the same as doing a 'naive' indexing, on big-endian, it is not! */ + +BLI_INLINE void gpuColor3P(GLuint rgb) +{ + GPU_IMMEDIATE->color[0] = (rgb >> 0) & 0xFF; + GPU_IMMEDIATE->color[1] = (rgb >> 8) & 0xFF; + GPU_IMMEDIATE->color[2] = (rgb >> 16) & 0xFF; + GPU_IMMEDIATE->color[3] = 255; +} + +BLI_INLINE void gpuColor4P(GLuint rgb, GLfloat a) +{ + GPU_IMMEDIATE->color[0] = (rgb >> 0) & 0xFF; + GPU_IMMEDIATE->color[1] = (rgb >> 8) & 0xFF; + GPU_IMMEDIATE->color[2] = (rgb >> 16) & 0xFF; + GPU_IMMEDIATE->color[3] = (GLubyte)(255.0f * a); +} + + + +BLI_INLINE void gpuGray3f(GLfloat luminance) +{ + GLubyte c = (GLubyte)(255.0 * luminance); + + GPU_IMMEDIATE->color[0] = c; + GPU_IMMEDIATE->color[1] = c; + GPU_IMMEDIATE->color[2] = c; + GPU_IMMEDIATE->color[3] = 255; +} + +BLI_INLINE void gpuGray4f(GLfloat luminance, GLfloat alpha) +{ + GLubyte c = (GLubyte)(255.0 * luminance); + + GPU_IMMEDIATE->color[0] = c; + GPU_IMMEDIATE->color[1] = c; + GPU_IMMEDIATE->color[2] = c; + GPU_IMMEDIATE->color[3] = (GLubyte)(255.0f * alpha); +} + + + +BLI_INLINE void gpuAlpha(GLfloat a) +{ + GPU_IMMEDIATE->color[3] = (GLubyte)(255.0f * a); +} + +BLI_INLINE void gpuMultAlpha(GLfloat factor) +{ + GPU_IMMEDIATE->color[3] = (GLubyte)(factor * (GLfloat)(GPU_IMMEDIATE->color[3])); +} + + + +BLI_INLINE void gpuGetColor4fv(GLfloat *__restrict color) +{ + color[0] = (GLfloat)(GPU_IMMEDIATE->color[0]) / 255.0f; + color[1] = (GLfloat)(GPU_IMMEDIATE->color[1]) / 255.0f; + color[2] = (GLfloat)(GPU_IMMEDIATE->color[2]) / 255.0f; + color[3] = (GLfloat)(GPU_IMMEDIATE->color[3]) / 255.0f; +} + +BLI_INLINE void gpuGetColor4ubv(GLubyte *__restrict color) +{ + color[0] = GPU_IMMEDIATE->color[0]; + color[1] = GPU_IMMEDIATE->color[1]; + color[2] = GPU_IMMEDIATE->color[2]; + color[3] = GPU_IMMEDIATE->color[3]; +} + + + +BLI_INLINE void gpuNormal3f(GLfloat x, GLfloat y, GLfloat z) +{ + GPU_IMMEDIATE->normal[0] = x; + GPU_IMMEDIATE->normal[1] = y; + GPU_IMMEDIATE->normal[2] = z; +} + +BLI_INLINE void gpuNormal3fv(const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->normal[0] = v[0]; + GPU_IMMEDIATE->normal[1] = v[1]; + GPU_IMMEDIATE->normal[2] = v[2]; +} + +BLI_INLINE void gpuNormal3sv(const GLshort *__restrict v) +{ + GPU_IMMEDIATE->normal[0] = v[0] / (float)SHRT_MAX; + GPU_IMMEDIATE->normal[1] = v[1] / (float)SHRT_MAX; + GPU_IMMEDIATE->normal[2] = v[2] / (float)SHRT_MAX; +} + + + +BLI_INLINE void gpuTexCoord2f(GLfloat s, GLfloat t) +{ + GPU_IMMEDIATE->texCoord[0][0] = s; + GPU_IMMEDIATE->texCoord[0][1] = t; + GPU_IMMEDIATE->texCoord[0][2] = 0; + GPU_IMMEDIATE->texCoord[0][3] = 1; +} + +BLI_INLINE void gpuTexCoord2fv(const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->texCoord[0][0] = v[0]; + GPU_IMMEDIATE->texCoord[0][1] = v[1]; + GPU_IMMEDIATE->texCoord[0][2] = 0; + GPU_IMMEDIATE->texCoord[0][3] = 1; +} + +BLI_INLINE void gpuTexCoord2iv(const GLint *__restrict v) +{ + GPU_IMMEDIATE->texCoord[0][0] = (GLfloat)(v[0]); + GPU_IMMEDIATE->texCoord[0][1] = (GLfloat)(v[1]); + GPU_IMMEDIATE->texCoord[0][2] = 0; + GPU_IMMEDIATE->texCoord[0][3] = 1; +} + +BLI_INLINE void gpuTexCoord3f(const GLfloat s, const GLfloat t, const GLfloat u) +{ + GPU_IMMEDIATE->texCoord[0][0] = s; + GPU_IMMEDIATE->texCoord[0][1] = t; + GPU_IMMEDIATE->texCoord[0][2] = u; + GPU_IMMEDIATE->texCoord[0][3] = 1; +} + +BLI_INLINE void gpuTexCoord3fv (const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->texCoord[0][0] = v[0]; + GPU_IMMEDIATE->texCoord[0][1] = v[1]; + GPU_IMMEDIATE->texCoord[0][2] = v[2]; + GPU_IMMEDIATE->texCoord[0][3] = 1; +} + + + +BLI_INLINE void gpuMultiTexCoord2f(GLint index, GLfloat s, GLfloat t) +{ + GPU_IMMEDIATE->texCoord[index][0] = s; + GPU_IMMEDIATE->texCoord[index][1] = t; + GPU_IMMEDIATE->texCoord[index][2] = 0; + GPU_IMMEDIATE->texCoord[index][3] = 1; +} + +BLI_INLINE void gpuMultiTexCoord2fv(GLint index, const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->texCoord[index][0] = v[0]; + GPU_IMMEDIATE->texCoord[index][1] = v[1]; + GPU_IMMEDIATE->texCoord[index][2] = 0; + GPU_IMMEDIATE->texCoord[index][3] = 1; +} + +BLI_INLINE void gpuMultiTexCoord3fv(GLint index, const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->texCoord[index][0] = v[0]; + GPU_IMMEDIATE->texCoord[index][1] = v[1]; + GPU_IMMEDIATE->texCoord[index][2] = v[2]; + GPU_IMMEDIATE->texCoord[index][3] = 1; +} + +BLI_INLINE void gpuMultiTexCoord4fv(GLint index, const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->texCoord[index][0] = v[0]; + GPU_IMMEDIATE->texCoord[index][1] = v[1]; + GPU_IMMEDIATE->texCoord[index][2] = v[2]; + GPU_IMMEDIATE->texCoord[index][3] = v[3]; +} + + + + +BLI_INLINE void gpuVertexAttrib2fv(GLsizei index, const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->attrib_f[index][0] = v[0]; + GPU_IMMEDIATE->attrib_f[index][1] = v[1]; + GPU_IMMEDIATE->attrib_f[index][2] = 0; + GPU_IMMEDIATE->attrib_f[index][3] = 1; +} + +BLI_INLINE void gpuVertexAttrib3fv(GLsizei index, const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->attrib_f[index][0] = v[0]; + GPU_IMMEDIATE->attrib_f[index][1] = v[1]; + GPU_IMMEDIATE->attrib_f[index][2] = v[2]; + GPU_IMMEDIATE->attrib_f[index][3] = 1; +} + +BLI_INLINE void gpuVertexAttrib4fv(GLsizei index, const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->attrib_f[index][0] = v[0]; + GPU_IMMEDIATE->attrib_f[index][1] = v[1]; + GPU_IMMEDIATE->attrib_f[index][2] = v[2]; + GPU_IMMEDIATE->attrib_f[index][3] = v[3]; +} + +BLI_INLINE void gpuVertexAttrib4ubv(GLsizei index, const GLubyte *__restrict v) +{ + GPU_IMMEDIATE->attrib_ub[index][0] = v[0]; + GPU_IMMEDIATE->attrib_ub[index][1] = v[1]; + GPU_IMMEDIATE->attrib_ub[index][2] = v[2]; + GPU_IMMEDIATE->attrib_ub[index][3] = v[3]; +} + + + +BLI_INLINE void gpuVertex2f(GLfloat x, GLfloat y) +{ + GPU_IMMEDIATE->vertex[0] = x; + GPU_IMMEDIATE->vertex[1] = y; + GPU_IMMEDIATE->vertex[2] = 0; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex2fv(const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->vertex[0] = v[0]; + GPU_IMMEDIATE->vertex[1] = v[1]; + GPU_IMMEDIATE->vertex[2] = 0; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex3f(GLfloat x, GLfloat y, GLfloat z) +{ + GPU_IMMEDIATE->vertex[0] = x; + GPU_IMMEDIATE->vertex[1] = y; + GPU_IMMEDIATE->vertex[2] = z; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); + } + +BLI_INLINE void gpuVertex3fv(const GLfloat *__restrict v) +{ + GPU_IMMEDIATE->vertex[0] = v[0]; + GPU_IMMEDIATE->vertex[1] = v[1]; + GPU_IMMEDIATE->vertex[2] = v[2]; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex3d(GLdouble x, GLdouble y, GLdouble z) +{ + GPU_IMMEDIATE->vertex[0] = (GLfloat)(x); + GPU_IMMEDIATE->vertex[1] = (GLfloat)(y); + GPU_IMMEDIATE->vertex[2] = (GLfloat)(z); + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex3dv(const GLdouble *__restrict v) +{ + GPU_IMMEDIATE->vertex[0] = (GLfloat)(v[0]); + GPU_IMMEDIATE->vertex[1] = (GLfloat)(v[1]); + GPU_IMMEDIATE->vertex[2] = (GLfloat)(v[2]); + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex2i(GLint x, GLint y) +{ + GPU_IMMEDIATE->vertex[0] = (GLfloat)(x); + GPU_IMMEDIATE->vertex[1] = (GLfloat)(y); + GPU_IMMEDIATE->vertex[2] = 0; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex2iv(const GLint *__restrict v) +{ + GPU_IMMEDIATE->vertex[0] = (GLfloat)(v[0]); + GPU_IMMEDIATE->vertex[1] = (GLfloat)(v[1]); + GPU_IMMEDIATE->vertex[2] = 0; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + +BLI_INLINE void gpuVertex2sv(const GLshort *__restrict v) +{ + GPU_IMMEDIATE->vertex[0] = (GLfloat)(v[0]); + GPU_IMMEDIATE->vertex[1] = (GLfloat)(v[1]); + GPU_IMMEDIATE->vertex[2] = 0; + GPU_IMMEDIATE->vertex[3] = 1; + + GPU_IMMEDIATE->copyVertex(); +} + + + +BLI_INLINE void gpuDraw(GLenum mode) +{ + GPU_CHECK_CAN_REPEAT(); + + GPU_IMMEDIATE->mode = mode; + gpu_end_buffer_gl(); +} + +BLI_INLINE void gpuRepeat(void) +{ + GPU_CHECK_CAN_REPEAT(); + + gpu_end_buffer_gl(); +} + + + +BLI_INLINE void gpuDrawElements(GLenum mode) +{ + GPU_IMMEDIATE->mode = mode; + gpu_draw_elements_gl(); +} + + +BLI_INLINE void gpuRepeatElements(void) +{ + gpu_draw_elements_gl(); +} + + +BLI_INLINE void gpuDrawRangeElements(GLenum mode) +{ + GPU_IMMEDIATE->mode = mode; + gpu_draw_range_elements_gl(); +} + +BLI_INLINE void gpuRepeatRangeElements(void) +{ + gpu_draw_range_elements_gl(); +} + + + +#ifdef __cplusplus +} +#endif + +#endif /* __GPU_IMMEDIATE_INLINE_H_ */ diff --git a/source/blender/gpu/GPU_init_exit.h b/source/blender/gpu/GPU_init_exit.h new file mode 100644 index 00000000000..3c7d2c95ca1 --- /dev/null +++ b/source/blender/gpu/GPU_init_exit.h @@ -0,0 +1,46 @@ +#ifndef _GPU_INIT_EXIT_H_ +#define _GPU_INIT_EXIT_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_init_exit.h + * \ingroup gpu + */ + +#ifdef __cplusplus +extern "C" { +#endif + +void GPU_init(void); +void GPU_exit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_INIT_EXIT_H_ */ diff --git a/source/blender/gpu/GPU_lighting.h b/source/blender/gpu/GPU_lighting.h new file mode 100644 index 00000000000..bff69c589d4 --- /dev/null +++ b/source/blender/gpu/GPU_lighting.h @@ -0,0 +1,77 @@ +#ifndef _GPU_LIGHTING_H_ +#define _GPU_LIGHTING_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_lighting.h + * \ingroup gpu + */ + +#include "BLI_sys_types.h" /* for bool */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct GPUbasiclight { + float position[4]; + float diffuse [4]; + float specular[4]; + + float constant_attenuation; + float linear_attenuation; + float quadratic_attenuation; + + float spot_direction[3]; + float spot_cutoff; + float spot_exponent; +} GPUbasiclight; + +void GPU_set_basic_material_shininess(int shininess); +void GPU_set_basic_material_specular(const float specular[4]); + +/* Set lights and also applies appropriate transformations on + the positions and spot directions */ +void GPU_set_basic_lights(int light_count, const GPUbasiclight lights[]); + +int GPU_get_basic_lights(GPUbasiclight lights_out[]); /* Lights out! Get it? :-) */ + +/* Set lights without transforming position or spot_direction. + Suitable for restoring a backup copy of previous light state. + Keeps position and spot position from getting transformed twice. */ +void GPU_restore_basic_lights(int light_count, const GPUbasiclight lights[]); + +/* A white directional light shining straight down with no attenuation or spot effects. + Same as the default legacy OpenGL light #0. */ +extern const GPUbasiclight GPU_DEFAULT_LIGHT; + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_LIGHTING_H_ */ diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 8d44ad87916..a111401343e 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -34,6 +34,8 @@ #include "DNA_listBase.h" +#include "BLI_sys_types.h" /* for bool */ + #ifdef __cplusplus extern "C" { #endif diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h new file mode 100644 index 00000000000..bfa48a934fd --- /dev/null +++ b/source/blender/gpu/GPU_matrix.h @@ -0,0 +1,107 @@ +#ifndef _GPU_MATRIX_H_ +#define _GPU_MATRIX_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov, Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_matrix.h + * \ingroup gpu + */ + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +void gpuPushMatrix(void); +void gpuPopMatrix(void); + +void gpuMatrixMode(GLenum mode); +GLenum gpuGetMatrixMode(void); + +void gpuLoadMatrix(const GLfloat m[16]); +const GLfloat* gpuGetMatrix(GLenum type, GLfloat m[16]); + +void gpuLoadIdentity(void); + +void gpuMultMatrix(const GLfloat m[16]); +void gpuMultMatrixd(const GLdouble m[16]); + +void gpuTranslate(GLfloat x, GLfloat y, GLfloat z); +void gpuScale(GLfloat x, GLfloat y, GLfloat z); +void gpuRotateVector(GLfloat deg, GLfloat vector[3]); +void gpuRotateAxis(GLfloat deg, char axis); +void gpuRotateRight(char type); + +void gpuOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); +void gpuFrustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); + +void gpuLoadOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); +void gpuLoadFrustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); + +void gpuLookAt(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ); + +void gpuProject(const GLfloat obj[3], const GLfloat model[16], const GLfloat proj[16], const GLint view[4], GLfloat win[3]); +GLboolean gpuUnProject(const GLfloat win[3], const GLfloat model[16], const GLfloat proj[16], const GLint view[4], GLfloat obj[3]); + +void GPU_feedback_vertex_3fv(GLenum type, GLfloat x, GLfloat y, GLfloat z, GLfloat out[3]); +void GPU_feedback_vertex_4fv(GLenum type, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat out[4]); +void GPU_feedback_vertex_4dv(GLenum type, GLdouble x, GLdouble y, GLdouble z, GLdouble w, GLdouble out[4]); + + + +#if defined(GLEW_ES_ONLY) + +/* ES 2.0 doesn't define these symbolic constants, but the matrix stack replacement library emulates them */ +/* (GL core has deprecated matrix stacks, but it should still be in the header) */ + +#ifndef GL_MODELVIEW_MATRIX +#define GL_MODELVIEW_MATRIX 0x0BA6 +#endif + +#ifndef GL_PROJECTION_MATRIX +#define GL_PROJECTION_MATRIX 0x0BA7 +#endif + +#ifndef GL_TEXTURE_MATRIX +#define GL_TEXTURE_MATRIX 0x0BA8 +#endif + +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif /* GPU_MATRIX_H */ diff --git a/source/blender/gpu/GPU_pixels.h b/source/blender/gpu/GPU_pixels.h new file mode 100644 index 00000000000..093c69b3c85 --- /dev/null +++ b/source/blender/gpu/GPU_pixels.h @@ -0,0 +1,119 @@ +#ifndef _GPU_PIXELS_H_ +#define _GPU_PIXELS_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_pixels.h + * \ingroup gpu + */ + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +typedef struct GPUbitmap { + GLsizei width, height; + GLsizei xorig, yorig; + const GLubyte* bitmap; +} GPUbitmap; + +typedef struct GPUpixels { + GLsizei width, height; + GLenum format; + GLenum type; + const GLvoid* pixels; +} GPUpixels; + + + +void GPU_bitmap_cache(GPUbitmap* bitmap); +void GPU_pixels_cache(GPUpixels* pixels); + +void GPU_bitmap_uncache(GPUbitmap* bitmap); +void GPU_pixels_uncache(GPUpixels* pixels); + +void GPU_pixels_zoom(GLfloat xfactor, GLfloat yfactor); +void GPU_get_pixels_zoom(GLfloat* xfactor_out, GLfloat *yfactor_out); + +void GPU_pixels_format(GLenum pname, GLint param); + +void GPU_pixels_uniform_1f(GLenum pname, GLfloat param); + +void GPU_pixels_pos_2f(GLfloat x, GLfloat y); +void GPU_pixels_pos_3f(GLfloat x, GLfloat y, GLfloat z); + +void GPU_bitmap(GPUbitmap* bitmap); +void GPU_pixels(GPUpixels* pixels); + +void GPU_pixels_begin(void); +void GPU_pixels_end (void); + + + +#if defined(GLEW_ES_ONLY) + +/* ES 2.0 doesn't define pixel transfer pnames, but the draw pixel replacement library emulates them */ + +#define GL_RED_SCALE 0x0D14 +#define GL_RED_BIAS 0x0D15 +#define GL_ZOOM_X 0x0D16 +#define GL_ZOOM_Y 0x0D17 +#define GL_GREEN_SCALE 0x0D18 +#define GL_GREEN_BIAS 0x0D19 +#define GL_BLUE_SCALE 0x0D1A +#define GL_BLUE_BIAS 0x0D1B +#define GL_ALPHA_SCALE 0x0D1C +#define GL_ALPHA_BIAS 0x0D1D + +#endif + + + +#if defined(GLEW_ES_ONLY) + +/* ES 2.0 doesn't define all pixel unpack parameters, but the drawPixel replacement library emulates them */ + +#ifndef GL_UNPACK_SWAP_BYTES +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#endif + +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_PIXELS_H_ */ diff --git a/source/blender/gpu/GPU_primitives.h b/source/blender/gpu/GPU_primitives.h new file mode 100644 index 00000000000..ca0bd8d8a89 --- /dev/null +++ b/source/blender/gpu/GPU_primitives.h @@ -0,0 +1,234 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file GPU_primitives.h + * \ingroup gpu + */ + +#ifndef __GPU_PRIMITIVES_H__ +#define __GPU_PRIMITIVES_H__ + + + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define GPU_NORMALS_SMOOTH 0 +#define GPU_NORMALS_FLAT 1 +#define GPU_NORMALS_NONE 2 + +#define GPU_DRAW_STYLE_FILL 0 +#define GPU_DRAW_STYLE_LINES 1 +#define GPU_DRAW_STYLE_SILHOUETTE 2 +#define GPU_DRAW_STYLE_POINTS 3 + +#define GPU_MAX_SEGS 128 + +typedef struct GPUprim3 { + GLfloat usegs; + GLfloat vsegs; + + GLenum normals; + GLenum drawStyle; + GLboolean flipNormals; + GLboolean texCoords; + + GLfloat thetaMin; + GLfloat thetaMax; + + union { + struct { + GLfloat point1[3]; + GLfloat point2[3]; + } sweep; /* cone, cylinder, disk , hyperboloid */ + + struct { + GLfloat radius; + GLfloat zMin; + GLfloat zMax; + } sphere; + + struct { + GLfloat rMax; + GLfloat zMin; + GLfloat zMax; + } paraboloid; + + struct { + GLfloat majorRadius; + GLfloat minorRadius; + GLfloat phiMin; + GLfloat phiMax; + } torus; + } params; +} GPUprim3; + +#define GPU_LOD_LO 8 +#define GPU_LOD_MID 16 +#define GPU_LOD_HI 32 + +extern const GPUprim3 GPU_PRIM_LOFI_SOLID; +extern const GPUprim3 GPU_PRIM_LOFI_SHADELESS; +extern const GPUprim3 GPU_PRIM_LOFI_WIRE; + +extern const GPUprim3 GPU_PRIM_MIDFI_SOLID; +extern const GPUprim3 GPU_PRIM_MIDFI_WIRE; + +extern const GPUprim3 GPU_PRIM_HIFI_SOLID; + +void gpuAppendCone(GPUprim3 *prim3, GLfloat radius, GLfloat height); +void gpuAppendCylinder(GPUprim3 *prim3, GLfloat radiusBase, GLfloat radiusTop, GLfloat height); +void gpuAppendSphere(GPUprim3 *prim3, GLfloat radius); + +void gpuDrawCone(GPUprim3 *prim3, GLfloat radius, GLfloat height); +void gpuDrawCylinder(GPUprim3 *prim3, GLfloat radiusBase, GLfloat radiusTop, GLfloat height); +void gpuDrawSphere(GPUprim3 *prim3, GLfloat radius); + +void gpuSingleCone(GPUprim3 *prim3, GLfloat radius, GLfloat height); +void gpuSingleCylinder(GPUprim3 *prim3, GLfloat radiusBase, GLfloat radiusTop, GLfloat height); +void gpuSingleSphere(GPUprim3 *prim3, GLfloat radius); + + + +void gpuSingleLinef(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); +void gpuSingleLinei(GLint x1, GLint y1, GLint x2, GLint y2); + +void gpuSingleFilledRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); +void gpuSingleFilledRecti(GLint x1, GLint y1, GLint x2, GLint y2); + +void gpuSingleWireRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); +void gpuSingleWireRecti(GLint x1, GLint y1, GLint x2, GLint y2); + + +void gpuAppendArc( + GLfloat x, + GLfloat y, + GLfloat start, + GLfloat angle, + GLfloat xradius, + GLfloat yradius, + GLint nsegments); + +void gpuDrawArc( + GLfloat x, + GLfloat y, + GLfloat start, + GLfloat angle, + GLfloat xradius, + GLfloat yradius, + GLint nsegments); + +void gpuSingleArc( + GLfloat x, + GLfloat y, + GLfloat start, + GLfloat angle, + GLfloat xradius, + GLfloat yradius, + GLint nsegments); + + + +void gpuAppendFastCircleXZ(GLfloat radius); +void gpuDrawFastCircleXZ(GLfloat radius); +void gpuSingleFastCircleXZ(GLfloat radius); + +void gpuAppendFastCircleXY(GLfloat radius); +void gpuDrawFastCircleXY(GLfloat radius); +void gpuSingleFastCircleXY(GLfloat radius); + + +void gpuAppendFastBall( + const GLfloat position[3], + float radius, + const GLfloat matrix[4][4]); + +void gpuDrawFastBall( + int mode, + const GLfloat position[3], + float radius, + const GLfloat matrix[4][4]); + +void gpuSingleFastBall( + int mode, + const GLfloat position[3], + float radius, + const GLfloat matrix[4][4]); + + + +void gpuAppendSpiral( + const GLfloat position[3], + float radius, + const GLfloat matrix[4][4], + int start); + +void gpuDrawSpiral( + const GLfloat position[3], + GLfloat radius, + GLfloat matrix[4][4], + int start); + +void gpuSingleSpiral( + const GLfloat position[3], + GLfloat radius, + GLfloat matrix[4][4], + int start); + + + +void gpuAppendDisk(GLfloat x, GLfloat y, GLfloat radius, GLint nsectors); +void gpuDrawDisk(GLfloat x, GLfloat y, GLfloat radius, GLint nsectors); +void gpuSingleDisk(GLfloat x, GLfloat y, GLfloat radius, GLint nsectors); + + + +void gpuSingleWireUnitCube(void); +void gpuSingleWireCube(GLfloat size); + +void gpuDrawSolidHalfCube(void); +void gpuDrawWireHalfCube(void); + + + +#ifdef __cplusplus +} +#endif + + + +#include "intern/gpu_primitives_inline.h" + + + +#endif /* __GPU_PRIMITIVES_H_ */ diff --git a/source/blender/gpu/GPU_raster.h b/source/blender/gpu/GPU_raster.h new file mode 100644 index 00000000000..0037d55c7df --- /dev/null +++ b/source/blender/gpu/GPU_raster.h @@ -0,0 +1,103 @@ +#ifndef _GPU_RASTER_H_ +#define _GPU_RASTER_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_raster.h + * \ingroup gpu + */ + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +/* OpenGL stipple defines */ +extern const GLubyte GPU_stipple_halftone [128]; +extern const GLubyte GPU_stipple_quarttone [128]; +extern const GLubyte GPU_stipple_diag_stripes_pos[128]; +extern const GLubyte GPU_stipple_diag_stripes_neg[128]; +extern const GLubyte GPU_stipple_checker_8px [128]; + + + +typedef enum GPURasterShaderOption { + GPU_RASTER_STIPPLE = (1<<0), /* polygon or line stippling */ + GPU_RASTER_AA = (1<<1), /* anti-aliasing */ + GPU_RASTER_POLYGON = (1<<2), /* choose polygon or line */ + + GPU_RASTER_OPTIONS_NUM = 3, + GPU_RASTER_OPTION_COMBINATIONS = (1<<GPU_RASTER_OPTIONS_NUM) +} GPURasterShaderOption; + + + +void GPU_raster_begin(void); +void GPU_raster_end (void); + +void GPU_raster_set_line_style(int factor); + +void gpuPolygonStipple(const GLubyte* mask); + +void gpuLineStipple(GLint factor, GLushort pattern); + +void gpuLineWidth(GLfloat width); +GLfloat gpuGetLineWidth(void); + +void gpuPolygonMode(GLenum mode); +GLenum gpuGetPolygonMode(void); + + + +#if defined(GLEW_ES_ONLY) + +/* ES 2.0 doesn't define LINE and FILL, but the immediate mode replacement library emulates PolygonMode */ +/* (GL core has deprecated PolygonMode, but it should still be in the header) */ + +#ifndef GL_LINE +#define GL_LINE 0x1B01 +#endif + +#ifndef GL_FILL +#define GL_FILL 0x1B02 +#endif + +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_RASTER_H_ */ diff --git a/source/blender/gpu/GPU_safety.h b/source/blender/gpu/GPU_safety.h new file mode 100644 index 00000000000..36e032d20c1 --- /dev/null +++ b/source/blender/gpu/GPU_safety.h @@ -0,0 +1,108 @@ +#ifndef _GPU_SAFETY_H_ +#define _GPU_SAFETY_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_safety.h + * \ingroup gpu + */ + + + +#ifndef GPU_SAFETY +#if !defined(NDEBUG) && defined(WITH_GPU_SAFETY) +#define GPU_SAFETY 1 +#else +#define GPU_SAFETY 0 +#endif +#endif + + + +#if GPU_SAFETY /* Define some useful, but potentially slow, checks for correct API usage. */ + +#include "BLI_utildefines.h" + +#include <stdlib.h> /* for abort */ + + + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_check(const char* file, int line, const char* text); + +#ifdef __cplusplus +} +#endif + + + +#define GPU_ASSERT(test) BLI_assert(test) + +/* Bails out of function even if assert or abort are disabled. + Needs a variable in scope to store results of the test. + Can be used in functions that return void if third argument is left blank */ +// XXX jwilkins: make this assert prettier +#define GPU_SAFE_RETURN(test, var, ret) \ + var = (bool)(test); \ + GPU_ASSERT(((void)#test, var)); \ + if (!var) { \ + return ret; \ + } + +#if WITH_ASSERT_ABORT +#define GPU_ABORT abort +#else +#define GPU_ABORT() ((void)0) +#endif + +#define GPU_CHECK_NO_ERROR() gpu_check(__FILE__, __LINE__, 0) + +#define GPU_CHECK(x) (gpu_check(__FILE__, __LINE__, "Before: " #x), (x), gpu_check(__FILE__, __LINE__, "After: " #x)) + + + +#else /* disable GPU_SAFETY */ + +#define GPU_ASSERT(test) ((void)0) + +#define GPU_SAFE_RETURN(test, var, ret) { (void)var; } + +#define GPU_ABORT() ((void)0) + +#define GPU_CHECK_NO_ERROR() ((void)0) + +#define GPU_CHECK(x) x + +#endif /* GPU_SAFETY */ + + + +#endif /* _GPU_SAFETY_H_ */ diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h index 1a274e0ad9d..9fe1b413a3c 100644 --- a/source/blender/gpu/GPU_select.h +++ b/source/blender/gpu/GPU_select.h @@ -23,13 +23,14 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file GPU_select.h +/** \file source/blender/gpu/GPU_select.h * \ingroup gpu */ #ifndef __GPU_SELECT__ #define __GPU_SELECT__ +#include "GPU_glew.h" #include "DNA_vec_types.h" /* rcft */ #include "BLI_sys_types.h" @@ -59,3 +60,4 @@ bool GPU_select_query_check_support(void); bool GPU_select_query_check_active(void); #endif + diff --git a/source/blender/gpu/GPU_simple_shader.h b/source/blender/gpu/GPU_simple_shader.h deleted file mode 100644 index c8fb1f09b04..00000000000 --- a/source/blender/gpu/GPU_simple_shader.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Brecht Van Lommel. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file GPU_simple_shader.h - * \ingroup gpu - */ - -#ifndef __GPU_SIMPLE_SHADER_H__ -#define __GPU_SIMPLE_SHADER_H__ - -#include "BLI_utildefines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Fixed Function Shader */ - -typedef enum GPUSimpleShaderOption { - GPU_SHADER_OVERRIDE_DIFFUSE = (1<<0), /* replace diffuse with glcolor */ - GPU_SHADER_LIGHTING = (1<<1), /* use lighting */ - GPU_SHADER_TWO_SIDED = (1<<2), /* flip normals towards viewer */ - GPU_SHADER_TEXTURE_2D = (1<<3), /* use 2D texture to replace diffuse color */ - - GPU_SHADER_SOLID_LIGHTING = (1<<4), /* use faster lighting (set automatically) */ - GPU_SHADER_OPTIONS_NUM = 5, - GPU_SHADER_OPTION_COMBINATIONS = (1<<GPU_SHADER_OPTIONS_NUM) -} GPUSimpleShaderOption; - -void GPU_simple_shaders_init(void); -void GPU_simple_shaders_exit(void); - -void GPU_simple_shader_bind(int options); -void GPU_simple_shader_unbind(void); - -void GPU_simple_shader_colors(const float diffuse[3], const float specular[3], - int shininess, float alpha); - -bool GPU_simple_shader_need_normals(void); - -/* Fixed Function Lighting */ - -typedef struct GPULightData { - float position[4]; - float diffuse[4]; - float specular[4]; - - float constant_attenuation; - float linear_attenuation; - float quadratic_attenuation; - - float spot_direction[3]; - float spot_cutoff; - float spot_exponent; -} GPULightData; - -void GPU_simple_shader_light_set(int light_num, GPULightData *light); -void GPU_simple_shader_light_set_viewer(bool local); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/source/blender/gpu/GPU_sprite.h b/source/blender/gpu/GPU_sprite.h new file mode 100644 index 00000000000..562ed300368 --- /dev/null +++ b/source/blender/gpu/GPU_sprite.h @@ -0,0 +1,65 @@ +#ifndef _GPU_SPRITE_H_ +#define _GPU_SPRITE_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_sprite.h + * \ingroup gpu + */ + +#include "BLI_sys_types.h" // for uint32_t + +#ifdef __cplusplus +extern "C" { +#endif + +void GPU_sprite_begin(void); +void GPU_sprite_end (void); + +void GPU_point_size (float size); +void GPU_sprite_size(float size); + +typedef enum GPUSpriteShaderOption { + GPU_SPRITE_CIRCULAR = (1<<0), /* */ + GPU_SPRITE_TEXTURE_2D = (1<<1), /* */ + + GPU_SPRITE_OPTIONS_NUM = 1, + GPU_SPRITE_OPTION_COMBINATIONS = (1<<GPU_SPRITE_OPTIONS_NUM) +} GPUSpriteShaderOption; + +void GPU_sprite_2f (float x, float y); +void GPU_sprite_2fv(const float v[2]); + +void GPU_sprite_3f (float x, float y, float z); +void GPU_sprite_3fv(const float v[3]); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_SPRITE_H_ */ diff --git a/source/blender/gpu/GPU_state_latch.h b/source/blender/gpu/GPU_state_latch.h new file mode 100644 index 00000000000..5a026572105 --- /dev/null +++ b/source/blender/gpu/GPU_state_latch.h @@ -0,0 +1,81 @@ +#ifndef _GPU_STATE_LATCH_H_ +#define _GPU_STATE_LATCH_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/GPU_state_latch.h + * \ingroup gpu + */ + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + +/* +OpenGL ES does not have state query functions for some state. + +These functions latch the value passed to them, +so that the current value can be queried later by a distance piece of code. + +Of course, this requires disciplined use of the correct function, so +these functions these replace should be include the gpu_deprecated.h header, +even if they aren't officially deprecated. + +If it makes sense to move one of these functions to another module, then do so, +they have nothing else in common besides the need for state query. + +*/ + +/* the DepthRange state latch also covers the fact the ES 2.0 doesn't accept + GLdouble for depth range by doing a conversion. */ +void gpuDepthRange(GLdouble near, GLdouble far); +void gpuGetDepthRange(GLdouble range[2]); + +void gpuBindTexture(GLenum target, GLuint name); +GLuint gpuGetTextureBinding2D(void); + +void gpuDepthMask(GLboolean flag); +GLboolean gpuGetDepthWriteMask(void); + +void gpuViewport(int x, int y, int width, int height); +void gpuGetViewport(int out[4]); + +/* feedback functions use the latched state to transform coordinates in the + same way as the legacy fixed function pipeline */ +GLfloat GPU_feedback_depth_range(GLfloat z); +void GPU_feedback_viewport_2fv(GLfloat x, GLfloat y, GLfloat out[2]); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/blender/gpu/GPU_utility.h b/source/blender/gpu/GPU_utility.h new file mode 100644 index 00000000000..8868ce9308d --- /dev/null +++ b/source/blender/gpu/GPU_utility.h @@ -0,0 +1,75 @@ +#ifndef _GPU_UTILITY_H_ +#define _GPU_UTILITY_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/GPU_utility.h + * \ingroup gpu + */ + +#include "GPU_glew.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + + +/* XXX jwilkins: temporary work around for MinGW32 build error */ +#ifdef __MINGW32__ +#undef GPU_ENABLE_STRING_MARKER +#define GPU_ENABLE_STRING_MARKER 0 +#endif + +#ifndef GPU_ENABLE_STRING_MARKER +#define GPU_ENABLE_STRING_MARKER 1 +#endif + +#if GL_GREMEDY_string_marker && GPU_ENABLE_STRING_MARKER +#define GPU_STRING_MARKER(msg) if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(sizeof(msg), msg) +#else +#define GPU_STRING_MARKER(msg) do {} while(0) +#endif + + + +const char* gpuErrorString(GLenum err); /* e.g. Invalid Enumeration */ +const char* gpuErrorSymbol(GLenum err); /* e.g. GL_INVALID_ENUM */ + + + +#ifdef __cplusplus +} +#endif + + + +#endif /* _GPU_UTILITY_H_ */ diff --git a/source/blender/gpu/intern/gpu_aspect.c b/source/blender/gpu/intern/gpu_aspect.c new file mode 100644 index 00000000000..b8532f87b27 --- /dev/null +++ b/source/blender/gpu/intern/gpu_aspect.c @@ -0,0 +1,248 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_aspect.c + * \ingroup gpu + */ + +/* my interface */ +#include "intern/gpu_aspect_intern.h" + +/* internal */ +#include "intern/gpu_select_intern.h" + +/* external */ +#include "MEM_guardedalloc.h" + + + +static GPUaspectimpl** GPU_ASPECT_FUNCS = NULL; + +static size_t aspect_max = 0; +static size_t aspect_free = 0; +static size_t aspect_fill = 0; + +static GPUaspectimpl dummy = { NULL }; + +static uint32_t current_aspect = -1; + +static bool in_select_mode = false; + + + +#if GPU_SAFETY +bool gpu_aspect_active(void) +{ + return current_aspect != -1; +} +#endif + + + +void gpu_aspect_init(void) +{ + const size_t count = 100; + + GPU_ASPECT_FUNCS = (GPUaspectimpl**)MEM_callocN(count * sizeof(GPUaspectimpl*), "GPU aspect function array"); + + aspect_max = count; + aspect_free = count; + aspect_fill = 0; +} + + + +void gpu_aspect_exit(void) +{ + MEM_freeN(GPU_ASPECT_FUNCS); + GPU_ASPECT_FUNCS = NULL; + + aspect_max = 0; + aspect_fill = 0; + aspect_free = 0; + + current_aspect = -1; +} + + + +bool GPU_commit_aspect(void) +{ + GPUaspectimpl* aspectImpl; + + GPU_ASSERT(gpu_aspect_active()); + GPU_ASSERT(in_select_mode == gpu_is_select_mode()); /* not allowed to change select/render mode while an aspect is active */ + + aspectImpl = GPU_ASPECT_FUNCS[current_aspect]; + + if (aspectImpl != NULL) { + if (in_select_mode) + return aspectImpl->select_commit != NULL ? aspectImpl->select_commit(aspectImpl->object) : false; + else + return aspectImpl->render_commit != NULL ? aspectImpl->render_commit(aspectImpl->object) : false; + } + + return false; +} + + + +void GPU_gen_aspects(size_t count, uint32_t* aspects) +{ + uint32_t src, dst; + + if (count == 0) { + return; + } + + if (count > aspect_free) { + aspect_max = aspect_max + count - aspect_free; + GPU_ASPECT_FUNCS = (GPUaspectimpl**)MEM_reallocN(GPU_ASPECT_FUNCS, aspect_max * sizeof(GPUaspectimpl*)); + aspect_free = count; + } + + src = aspect_fill; + dst = 0; + + while (dst < count) { + if (!GPU_ASPECT_FUNCS[src]) { + GPU_ASPECT_FUNCS[src] = &dummy; + aspects[dst] = src; + dst++; + aspect_fill = dst; + aspect_free--; + } + + src++; + } +} + + + +void GPU_delete_aspects(size_t count, const uint32_t* aspects) +{ + uint32_t i; + + for (i = 0; i < count; i++) { + if (aspects[i] < aspect_fill) { + aspect_fill = aspects[i]; + } + + GPU_ASPECT_FUNCS[aspects[i]] = NULL; + } +} + + + +void GPU_aspect_impl(uint32_t aspect, GPUaspectimpl* aspectImpl) +{ + if (aspectImpl != NULL) + GPU_ASPECT_FUNCS[aspect] = aspectImpl; + else + GPU_ASPECT_FUNCS[aspect] = &dummy; +} + + + +bool GPU_aspect_begin(uint32_t aspect, void* param) +{ + GPUaspectimpl* aspectImpl; + + GPU_ASSERT(!gpu_aspect_active()); + + current_aspect = aspect; + + in_select_mode = gpu_is_select_mode(); + + aspectImpl = GPU_ASPECT_FUNCS[aspect]; + + if (aspectImpl != NULL) { + aspectImpl->current_param = param; + + if (in_select_mode) + return aspectImpl->select_begin != NULL ? aspectImpl->select_begin(aspectImpl->object, param) : true; + else + return aspectImpl->render_begin != NULL ? aspectImpl->render_begin(aspectImpl->object, param) : true; + } + + return true; +} + + + +bool GPU_aspect_end(void) +{ + GPUaspectimpl* aspectImpl; + void* param; + + GPU_ASSERT(gpu_aspect_active()); + GPU_ASSERT(in_select_mode == gpu_is_select_mode()); /* not allowed to change select/render mode while an aspect is active */ + + aspectImpl = GPU_ASPECT_FUNCS[current_aspect]; + + current_aspect = -1; + + if (aspectImpl != NULL) { + param = aspectImpl->current_param; + aspectImpl->current_param = NULL; + + if (in_select_mode) + return aspectImpl->select_end != NULL ? aspectImpl->select_end(aspectImpl->object, param) : true; + else + return aspectImpl->render_end != NULL ? aspectImpl->render_end(aspectImpl->object, param) : true; + } + + return true; +} + + + +void GPU_aspect_enable(uint32_t aspect, uint32_t options) +{ + GPUaspectimpl* aspectImpl; + + GPU_ASSERT(aspect < aspect_max); + + aspectImpl = GPU_ASPECT_FUNCS[aspect]; + + if (aspectImpl != NULL && aspectImpl->enable != NULL) + aspectImpl->enable(aspectImpl->object, options); +} + + + +void GPU_aspect_disable(uint32_t aspect, uint32_t options) +{ + GPUaspectimpl* aspectImpl; + + GPU_ASSERT(aspect < aspect_max); + + aspectImpl = GPU_ASPECT_FUNCS[aspect]; + + if (aspectImpl != NULL && aspectImpl->disable != NULL ) + aspectImpl->disable(aspectImpl->object, options); +} diff --git a/source/blender/gpu/intern/gpu_aspect_intern.h b/source/blender/gpu/intern/gpu_aspect_intern.h new file mode 100644 index 00000000000..5cad64c8f6b --- /dev/null +++ b/source/blender/gpu/intern/gpu_aspect_intern.h @@ -0,0 +1,54 @@ +#ifndef _GPU_ASPECT_INTERN_H_ +#define _GPU_ASPECT_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_aspect_intern.h + * \ingroup gpu + */ + +#include "GPU_aspect.h" + +#include "GPU_safety.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_aspect_init(void); +void gpu_aspect_exit(void); + +#if GPU_SAFETY +bool gpu_aspect_active(void); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* GPU_ASPECT_INTERN_H */ diff --git a/source/blender/gpu/intern/gpu_basic.c b/source/blender/gpu/intern/gpu_basic.c new file mode 100644 index 00000000000..6169e8daf11 --- /dev/null +++ b/source/blender/gpu/intern/gpu_basic.c @@ -0,0 +1,330 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Brecht Van Lommel, Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_basic.c + * \ingroup gpu + */ + +/* GLSL shaders to replace fixed function OpenGL materials and lighting. These + * are deprecated in newer OpenGL versions and missing in OpenGL ES 2.0. Also, + * two sided lighting is no longer natively supported on NVidia cards which + * results in slow software fallback. + * + * Todo: + * x Replace glLight and glMaterial functions entirely with GLSL uniforms, to make OpenGL ES 2.0 work. + * x Replace glTexCoord and glColor with generic attributes. + * x Optimize for case where fewer than 3 or 8 lights are used. + * - Optimize for case where specular is not used. + * - Optimize for case where no texture matrix is used. + */ + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + +/* my interface */ +#include "intern/gpu_basic_intern.h" + +/* my library */ +#include "GPU_extensions.h" +#include "GPU_safety.h" +#include "GPU_state_latch.h" + +/* internal */ +#include "intern/gpu_clipping_intern.h" +#include "intern/gpu_common_intern.h" +#include "intern/gpu_lighting_intern.h" +#include "intern/gpu_matrix_intern.h" + +/* external */ + +#include "BLI_math.h" +#include "BLI_dynstr.h" + +#include "MEM_guardedalloc.h" + +/* standard */ +#include <string.h> + + + +/* State */ + +static struct BASIC_SHADER { + uint32_t options; + + GPUShader* gpushader[GPU_BASIC_OPTION_COMBINATIONS]; + bool failed [GPU_BASIC_OPTION_COMBINATIONS]; + GPUcommon common [GPU_BASIC_OPTION_COMBINATIONS]; + +} BASIC_SHADER; + + + +/* Init / exit */ + +void gpu_basic_init(void) +{ + memset(&BASIC_SHADER, 0, sizeof(BASIC_SHADER)); + +#if 0 + { /* for testing purposes, mark all shaders as failed*/ + int i; + for (i = 0; i < GPU_BASIC_OPTION_COMBINATIONS; i++) + BASIC_SHADER.failed[i] = true; + } +#endif +} + + + +void gpu_basic_exit(void) +{ + int i; + + for (i = 0; i < GPU_BASIC_OPTION_COMBINATIONS; i++) + if (BASIC_SHADER.gpushader[i] != NULL) + GPU_shader_free(BASIC_SHADER.gpushader[i]); +} + + + +/* Shader feature enable/disable */ + +void gpu_basic_enable(uint32_t options) +{ + GPU_ASSERT(!(options & GPU_BASIC_FAST_LIGHTING)); + + BASIC_SHADER.options |= options; +} + + + +void gpu_basic_disable(uint32_t options) +{ + BASIC_SHADER.options &= ~options; +} + + + +/* Shader lookup / create */ + +static uint32_t tweak_options(void) +{ + uint32_t options; + + options = BASIC_SHADER.options; + + /* detect if we can do faster lighting for solid draw mode */ + if ( BASIC_SHADER.options & GPU_BASIC_LIGHTING && + !(BASIC_SHADER.options & GPU_BASIC_LOCAL_VIEWER) && + gpu_lighting_is_fast()) + { + options |= GPU_BASIC_FAST_LIGHTING; + } + + if (gpuGetTextureBinding2D() == 0) + options &= ~GPU_BASIC_TEXTURE_2D; + + return options; +} + + + +static void basic_shader_bind(void) +{ + /* glsl code */ + extern const char datatoc_gpu_shader_basic_vert_glsl[]; + extern const char datatoc_gpu_shader_basic_frag_glsl[]; + + const uint32_t tweaked_options = tweak_options(); + + /* create shader if it doesn't exist yet */ + if (BASIC_SHADER.gpushader[tweaked_options] != NULL) { + GPU_shader_bind(BASIC_SHADER.gpushader[tweaked_options]); + gpu_set_common(BASIC_SHADER.common + tweaked_options); + } + else if (!BASIC_SHADER.failed[tweaked_options]) { + DynStr* vert = BLI_dynstr_new(); + DynStr* frag = BLI_dynstr_new(); + DynStr* defs = BLI_dynstr_new(); + + char* vert_cstring; + char* frag_cstring; + char* defs_cstring; + + char nickname[20]; + + gpu_include_common_vert(vert); + BLI_dynstr_append(vert, datatoc_gpu_shader_basic_vert_glsl); + + gpu_include_common_frag(frag); + BLI_dynstr_append(frag, datatoc_gpu_shader_basic_frag_glsl); + + gpu_include_common_defs(defs); + + if (tweaked_options & GPU_BASIC_TWO_SIDE) + BLI_dynstr_append(defs, "#define USE_TWO_SIDE\n"); + + if (tweaked_options & GPU_BASIC_TEXTURE_2D) + BLI_dynstr_append(defs, "#define USE_TEXTURE_2D\n"); + + if (tweaked_options & GPU_BASIC_LOCAL_VIEWER) + BLI_dynstr_append(defs, "#define USE_LOCAL_VIEWER\n"); + + if (tweaked_options & GPU_BASIC_SMOOTH) + BLI_dynstr_append(defs, "#define USE_SMOOTH\n"); + + if (tweaked_options & GPU_BASIC_LIGHTING) { + BLI_dynstr_append(defs, "#define USE_LIGHTING\n"); + BLI_dynstr_append(defs, "#define USE_SPECULAR\n"); + + if (tweaked_options & GPU_BASIC_FAST_LIGHTING) + BLI_dynstr_append(defs, "#define USE_FAST_LIGHTING\n"); + } + + vert_cstring = BLI_dynstr_get_cstring(vert); + frag_cstring = BLI_dynstr_get_cstring(frag); + defs_cstring = BLI_dynstr_get_cstring(defs); + + sprintf(nickname, "Basic[0x%04X]", tweaked_options); + + BASIC_SHADER.gpushader[tweaked_options] = + GPU_shader_create(nickname, vert_cstring, frag_cstring, NULL, defs_cstring); + + MEM_freeN(vert_cstring); + MEM_freeN(frag_cstring); + MEM_freeN(defs_cstring); + + BLI_dynstr_free(vert); + BLI_dynstr_free(frag); + BLI_dynstr_free(defs); + + if (BASIC_SHADER.gpushader[tweaked_options] != NULL) { + gpu_common_get_symbols(BASIC_SHADER.common + tweaked_options, BASIC_SHADER.gpushader[tweaked_options]); + gpu_set_common(BASIC_SHADER.common + tweaked_options); + + GPU_shader_bind(BASIC_SHADER.gpushader[tweaked_options]); + } + else { + BASIC_SHADER.failed[tweaked_options] = true; + gpu_set_common(NULL); + } + } + else { + gpu_set_common(NULL); + } +} + + + +/* Bind / Unbind */ + + + +void gpu_basic_bind(void) +{ + bool glsl_support = GPU_glsl_support(); + + if (glsl_support) { + basic_shader_bind(); + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK_NO_ERROR(); + + if (!glsl_support) { + if (BASIC_SHADER.options & GPU_BASIC_LIGHTING) + glEnable(GL_LIGHTING); + else + glDisable(GL_LIGHTING); + + if (BASIC_SHADER.options & GPU_BASIC_TEXTURE_2D) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + if (BASIC_SHADER.options & GPU_BASIC_TWO_SIDE) + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + else + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); + + if (BASIC_SHADER.options & GPU_BASIC_LOCAL_VIEWER) + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); + else + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); + + if (BASIC_SHADER.options & GPU_BASIC_SMOOTH) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); + + gpu_toggle_clipping(BASIC_SHADER.options & GPU_BASIC_CLIPPING); + } + + GPU_CHECK_NO_ERROR(); +#endif + + if (BASIC_SHADER.options & GPU_BASIC_LIGHTING) { + gpu_commit_lighting(); + gpu_commit_material(); + } + + if (BASIC_SHADER.options & GPU_BASIC_CLIPPING) { + gpu_commit_clipping(); + } + + gpu_commit_matrix(); +} + + + +void gpu_basic_unbind(void) +{ + if (GPU_glsl_support()) + GPU_shader_unbind(); + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK_NO_ERROR(); + + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); + glShadeModel(GL_FLAT); + gpu_toggle_clipping(false); + + GPU_CHECK_NO_ERROR(); +#endif +} + + + +bool GPU_basic_needs_normals(void) +{ + return BASIC_SHADER.options & GPU_BASIC_LIGHTING; // Temporary hack. Should be solved outside of this file. +} diff --git a/source/blender/gpu/intern/gpu_basic_intern.h b/source/blender/gpu/intern/gpu_basic_intern.h new file mode 100644 index 00000000000..e4348f6063f --- /dev/null +++ b/source/blender/gpu/intern/gpu_basic_intern.h @@ -0,0 +1,56 @@ +#ifndef _GPU_BASIC_INTERN_H_ +#define _GPU_BASIC_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Brecht Van Lommel, Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_basic_intern.h + * \ingroup gpu + */ + +#include "GPU_basic.h" + +#include "BLI_sys_types.h" /* for uint32_t */ + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_basic_init(void); +void gpu_basic_exit(void); + +void gpu_basic_enable (uint32_t options); +void gpu_basic_disable(uint32_t options); + +void gpu_basic_bind (void); +void gpu_basic_unbind(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_BASIC_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_blender_aspect.c b/source/blender/gpu/intern/gpu_blender_aspect.c new file mode 100644 index 00000000000..3c2bcafc8f5 --- /dev/null +++ b/source/blender/gpu/intern/gpu_blender_aspect.c @@ -0,0 +1,262 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_blender_aspect.c + * \ingroup gpu + */ + +/* my interface */ +#include "intern/gpu_blender_aspect_intern.h" + +/* internal */ +#include "intern/gpu_basic_intern.h" +#include "intern/gpu_font_intern.h" +#include "intern/gpu_pixels_intern.h" +#include "intern/gpu_raster_intern.h" +#include "intern/gpu_select_intern.h" +#include "intern/gpu_sprite_intern.h" + +/* external */ +#include "BLI_utildefines.h" + + + +uint32_t GPU_ASPECT_BASIC = 0; +uint32_t GPU_ASPECT_CODEGEN = 0; +uint32_t GPU_ASPECT_FONT = 0; +uint32_t GPU_ASPECT_PIXELS = 0; +uint32_t GPU_ASPECT_RASTER = 0; +uint32_t GPU_ASPECT_SPRITE = 0; + + + +static bool font_end(const void* UNUSED(object), void* UNUSED(param)) +{ + gpu_font_unbind(); + + return true; +} + +static bool font_commit(const void* UNUSED(object)) +{ + gpu_font_bind(); + + return true; +} + +GPUaspectimpl GPU_ASPECTIMPL_FONT = { + NULL, /* render_begin */ + font_end, /* render_end */ + font_commit, /* render_commit */ + NULL, /* select_begin */ + NULL, /* select_end */ + NULL, /* select_commit */ + NULL, /* enable */ + NULL, /* disable */ +}; + + + +static bool pixels_end(const void* UNUSED(object), void* UNUSED(param)) +{ + gpu_pixels_unbind(); + + return true; +} + +static bool pixels_commit(const void* UNUSED(object)) +{ + gpu_pixels_bind(); + + return true; +} + +GPUaspectimpl GPU_ASPECTIMPL_PIXELS = { + NULL, /* render_begin */ + pixels_end, /* render_end */ + pixels_commit, /* render_commit */ + NULL, /* select_begin */ + NULL, /* select_end */ + NULL, /* select_commit */ + NULL, /* enable */ + NULL, /* disable */ +}; + + + +static bool basic_end(const void* UNUSED(object), void* UNUSED(param)) +{ + gpu_basic_unbind(); + + return true; +} + +static bool basic_commit(const void* UNUSED(object)) +{ + gpu_basic_bind(); + + return true; +} + +static void basic_enable(const void* UNUSED(object), uint32_t options) +{ + gpu_basic_enable(options); +} + +static void basic_disable(const void* UNUSED(object), uint32_t options) +{ + gpu_basic_disable(options); +} + +GPUaspectimpl GPU_ASPECTIMPL_BASIC = { + NULL, /* render_begin */ + basic_end, /* render_end */ + basic_commit, /* render_commit */ + gpu_default_select_begin, /* select_begin */ + gpu_default_select_end, /* select_end */ + gpu_default_select_commit, /* select_commit */ + basic_enable, /* enable */ + basic_disable /* disable */ +}; + + + +GPUaspectimpl GPU_ASPECTIMPL_CODEGEN = { + NULL, /* render_begin */ + NULL, /* render_end */ + NULL, /* render_commit */ + NULL, /* select_begin */ + NULL, /* select_end */ + NULL, /* select_commit */ + NULL, /* enable */ + NULL, /* disable */ +}; + + + +static bool raster_end(const void* UNUSED(object), void* UNUSED(param)) +{ + gpu_raster_unbind(); + + return true; +} + +static bool raster_commit(const void* UNUSED(object)) +{ + gpu_raster_bind(); + + return true; +} + +static void raster_enable(const void* UNUSED(object), uint32_t options) +{ + gpu_raster_enable(options); +} + +static void raster_disable(const void* UNUSED(object), uint32_t options) +{ + gpu_raster_disable(options); +} + +GPUaspectimpl GPU_ASPECTIMPL_RASTER = { + NULL, /* render_begin */ + raster_end, /* render_end */ + raster_commit, /* render_commit */ + gpu_default_select_begin, /* select_begin */ + gpu_default_select_end, /* select_end */ + gpu_default_select_commit, /* select_commit */ + raster_enable, /* enable */ + raster_disable /* disable */ +}; + + + +static bool sprite_end(const void* UNUSED(object), void* UNUSED(param)) +{ + gpu_sprite_unbind(); + + return true; +} + +static bool sprite_commit(const void* UNUSED(object)) +{ + gpu_sprite_bind(); + + return true; +} + +static void sprite_enable(const void* UNUSED(object), uint32_t options) +{ + gpu_sprite_enable(options); +} + +static void sprite_disable(const void* UNUSED(object), uint32_t options) +{ + gpu_sprite_disable(options); +} + +GPUaspectimpl GPU_ASPECTIMPL_SPRITE = { + NULL, /* begin */ + sprite_end, /* end */ + sprite_commit, /* commit */ + gpu_default_select_begin, /* select_begin */ + gpu_default_select_end, /* select_end */ + gpu_default_select_commit, /* select_commit */ + sprite_enable, /* enable */ + sprite_disable /* disable */ +}; + + + +void gpu_blender_aspect_init(void) +{ + GPU_gen_aspects(1, &GPU_ASPECT_BASIC); + GPU_gen_aspects(1, &GPU_ASPECT_CODEGEN); + GPU_gen_aspects(1, &GPU_ASPECT_FONT); + GPU_gen_aspects(1, &GPU_ASPECT_PIXELS); + GPU_gen_aspects(1, &GPU_ASPECT_RASTER); + GPU_gen_aspects(1, &GPU_ASPECT_SPRITE); + + GPU_aspect_impl(GPU_ASPECT_BASIC, &GPU_ASPECTIMPL_BASIC); + GPU_aspect_impl(GPU_ASPECT_BASIC, &GPU_ASPECTIMPL_CODEGEN); + GPU_aspect_impl(GPU_ASPECT_FONT, &GPU_ASPECTIMPL_FONT); + GPU_aspect_impl(GPU_ASPECT_PIXELS, &GPU_ASPECTIMPL_PIXELS); + GPU_aspect_impl(GPU_ASPECT_RASTER, &GPU_ASPECTIMPL_RASTER); + GPU_aspect_impl(GPU_ASPECT_SPRITE, &GPU_ASPECTIMPL_SPRITE); +} + + + +void gpu_blender_aspect_exit(void) +{ + GPU_delete_aspects(1, &GPU_ASPECT_BASIC); + GPU_delete_aspects(1, &GPU_ASPECT_CODEGEN); + GPU_delete_aspects(1, &GPU_ASPECT_FONT); + GPU_delete_aspects(1, &GPU_ASPECT_PIXELS); + GPU_delete_aspects(1, &GPU_ASPECT_RASTER); + GPU_delete_aspects(1, &GPU_ASPECT_SPRITE); +} diff --git a/source/blender/gpu/intern/gpu_blender_aspect_intern.h b/source/blender/gpu/intern/gpu_blender_aspect_intern.h new file mode 100644 index 00000000000..045d366af03 --- /dev/null +++ b/source/blender/gpu/intern/gpu_blender_aspect_intern.h @@ -0,0 +1,48 @@ +#ifndef _GPU_BLENDER_ASPECT_INTERN_H_ +#define _GPU_BLENDER_ASPECT_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_aspectimpl_intern.h + * \ingroup gpu + */ + +#include "GPU_blender_aspect.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_blender_aspect_init(void); +void gpu_blender_aspect_exit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_BLENDER_ASPECT_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 5d2c9cd3a90..6eda6d35ff3 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -32,13 +32,22 @@ * with fall-back to vertex arrays. */ -#include <limits.h> -#include <stddef.h> -#include <string.h> +/* my interface */ +#include "GPU_buffers.h" -#include "GL/glew.h" +/* internal */ +#include "intern/gpu_extensions_intern.h" -#include "MEM_guardedalloc.h" +/* my library */ +#include "GPU_draw.h" +#include "GPU_glew.h" + +/* external */ + +#include "BKE_ccg.h" +#include "BKE_DerivedMesh.h" +#include "BKE_paint.h" +#include "BKE_pbvh.h" #include "BLI_bitmap.h" #include "BLI_math.h" @@ -46,6 +55,8 @@ #include "BLI_ghash.h" #include "BLI_threads.h" + +#include "bmesh.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" @@ -55,12 +66,15 @@ #include "BKE_material.h" #include "BKE_pbvh.h" +#include "DNA_meshdata_types.h" #include "DNA_userdef_types.h" -#include "GPU_buffers.h" -#include "GPU_draw.h" +#include "MEM_guardedalloc.h" -#include "bmesh.h" +/* standard */ +#include <limits.h> +#include <stddef.h> +#include <string.h> typedef enum { GPU_BUFFER_VERTEX_STATE = (1 << 0), @@ -159,7 +173,7 @@ static void gpu_buffer_pool_delete_last(GPUBufferPool *pool) /* delete the buffer's data */ if (useVBOs) - glDeleteBuffersARB(1, &last->id); + gpu_glDeleteBuffers(1, &last->id); else MEM_freeN(last->pointer); @@ -194,7 +208,7 @@ static void gpu_buffer_pool_free_unused(GPUBufferPool *pool) while (pool->totbuf) gpu_buffer_pool_delete_last(pool); - glDeleteBuffersARB(pool->totpbvhbufids, pool->pbvhbufids); + gpu_glDeleteBuffers(pool->totpbvhbufids, pool->pbvhbufids); pool->totpbvhbufids = 0; BLI_mutex_unlock(&buffer_mutex); @@ -283,14 +297,14 @@ static GPUBuffer *gpu_buffer_alloc_intern(int size) if (useVBOs == 1) { /* create a new VBO and initialize it to the requested * size */ - glGenBuffersARB(1, &buf->id); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf->id); - glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glGenBuffers(1, &buf->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, buf->id); + gpu_glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); } else { buf->pointer = MEM_mallocN(size, "GPUBuffer.pointer"); - + /* purpose of this seems to be dealing with * out-of-memory errors? looks a bit iffy to me * though, at least on Linux I expect malloc() would @@ -354,8 +368,8 @@ static void gpu_buffer_free_intern(GPUBuffer *buffer) * buffer, so increase pool size */ if (pool->maxsize == pool->totbuf) { pool->maxsize += MAX_FREE_GPU_BUFFERS; - pool->buffers = MEM_reallocN(pool->buffers, - sizeof(GPUBuffer *) * pool->maxsize); + pool->buffers = (GPUBuffer**)MEM_reallocN(pool->buffers, + sizeof(GPUBuffer *) * pool->maxsize); } } @@ -634,11 +648,11 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object, while (!success) { /* bind the buffer and discard previous data, * avoids stalling gpu */ - glBindBufferARB(target, buffer->id); - glBufferDataARB(target, buffer->size, NULL, GL_STATIC_DRAW_ARB); + gpu_glBindBuffer(target, buffer->id); + gpu_glBufferData(target, buffer->size, NULL, GL_STATIC_DRAW); /* attempt to map the buffer */ - if (!(varray = glMapBufferARB(target, GL_WRITE_ONLY_ARB))) { + if (!(varray = gpu_glMapBuffer(target, GL_WRITE_ONLY))) { /* failed to map the buffer; delete it */ gpu_buffer_free_intern(buffer); gpu_buffer_pool_delete_last(pool); @@ -672,10 +686,10 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object, /* glUnmapBuffer returns GL_FALSE if * the data store is corrupted; retry * in that case */ - uploaded = glUnmapBufferARB(target); + uploaded = gpu_glUnmapBuffer(target); } } - glBindBufferARB(target, 0); + gpu_glBindBuffer(target, 0); } else { /* VBO not supported, use vertex array fallback */ @@ -820,7 +834,7 @@ static void GPU_buffer_copy_uv(DerivedMesh *dm, float *varray, int *index, int * if (!(mtface = DM_get_tessface_data_layer(dm, CD_MTFACE))) return; f = dm->getTessFaceArray(dm); - + totface = dm->getNumTessFaces(dm); for (i = 0; i < totface; i++, f++) { start = index[mat_orig_to_new[f->mat_nr]]; @@ -997,13 +1011,13 @@ typedef struct { } GPUBufferTypeSettings; const GPUBufferTypeSettings gpu_buffer_type_settings[] = { - {GPU_buffer_copy_vertex, GL_ARRAY_BUFFER_ARB, 3}, - {GPU_buffer_copy_normal, GL_ARRAY_BUFFER_ARB, 3}, - {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER_ARB, 3}, - {GPU_buffer_copy_uv, GL_ARRAY_BUFFER_ARB, 2}, - {GPU_buffer_copy_uv_texpaint, GL_ARRAY_BUFFER_ARB, 4}, - {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER_ARB, 2}, - {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4} + {GPU_buffer_copy_vertex, GL_ARRAY_BUFFER, 3}, + {GPU_buffer_copy_normal, GL_ARRAY_BUFFER, 3}, + {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER, 3}, + {GPU_buffer_copy_uv, GL_ARRAY_BUFFER, 2}, + {GPU_buffer_copy_uv_texpaint, GL_ARRAY_BUFFER, 4}, + {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER, 2}, + {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER, 4}, }; /* get the GPUDrawObject buffer associated with a type */ @@ -1106,13 +1120,13 @@ void GPU_vertex_setup(DerivedMesh *dm) glEnableClientState(GL_VERTEX_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->points->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id); glVertexPointer(3, GL_FLOAT, 0, 0); } else { glVertexPointer(3, GL_FLOAT, 0, dm->drawObject->points->pointer); } - + GLStates |= GPU_BUFFER_VERTEX_STATE; } @@ -1123,7 +1137,7 @@ void GPU_normal_setup(DerivedMesh *dm) glEnableClientState(GL_NORMAL_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->normals->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->normals->id); glNormalPointer(GL_FLOAT, 0, 0); } else { @@ -1140,7 +1154,7 @@ void GPU_uv_setup(DerivedMesh *dm) glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uv->id); glTexCoordPointer(2, GL_FLOAT, 0, 0); } else { @@ -1157,7 +1171,7 @@ void GPU_texpaint_uv_setup(DerivedMesh *dm) glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id); glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), 0); glClientActiveTexture(GL_TEXTURE2); glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -1203,7 +1217,7 @@ void GPU_color_setup(DerivedMesh *dm, int colType) glEnableClientState(GL_COLOR_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->colors->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->colors->id); glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); } else { @@ -1223,17 +1237,17 @@ void GPU_edge_setup(DerivedMesh *dm) glEnableClientState(GL_VERTEX_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->points->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id); glVertexPointer(3, GL_FLOAT, 0, 0); } else { glVertexPointer(3, GL_FLOAT, 0, dm->drawObject->points->pointer); } - + GLStates |= GPU_BUFFER_VERTEX_STATE; if (useVBOs) - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, dm->drawObject->edges->id); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->edges->id); GLStates |= GPU_BUFFER_ELEMENT_STATE; } @@ -1245,7 +1259,7 @@ void GPU_uvedge_setup(DerivedMesh *dm) glEnableClientState(GL_VERTEX_ARRAY); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uvedges->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uvedges->id); glVertexPointer(2, GL_FLOAT, 0, 0); } else { @@ -1293,7 +1307,7 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) { if (attribData[i].index != -1) { - glDisableVertexAttribArrayARB(attribData[i].index); + gpu_glDisableVertexAttribArray(attribData[i].index); } else break; @@ -1301,10 +1315,10 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda elementsize = GPU_attrib_element_size(data, numdata); if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id); for (i = 0; i < numdata; i++) { - glEnableVertexAttribArrayARB(data[i].index); - glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type, + gpu_glEnableVertexAttribArray(data[i].index); + gpu_glVertexAttribPointer(data[i].index, data[i].size, data[i].type, GL_FALSE, elementsize, (void *)offset); offset += data[i].size * GPU_typesize(data[i].type); @@ -1316,8 +1330,8 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda } else { for (i = 0; i < numdata; i++) { - glEnableVertexAttribArrayARB(data[i].index); - glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type, + gpu_glEnableVertexAttribArray(data[i].index); + gpu_glVertexAttribPointer(data[i].index, data[i].size, data[i].type, GL_FALSE, elementsize, (char *)buffer->pointer + offset); offset += data[i].size * GPU_typesize(data[i].type); } @@ -1344,7 +1358,7 @@ void GPU_buffer_unbind(void) glDisableClientState(GL_COLOR_ARRAY); if (GLStates & GPU_BUFFER_ELEMENT_STATE) { if (useVBOs) { - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } } GLStates &= ~(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE | @@ -1353,14 +1367,14 @@ void GPU_buffer_unbind(void) for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) { if (attribData[i].index != -1) { - glDisableVertexAttribArrayARB(attribData[i].index); + gpu_glDisableVertexAttribArray(attribData[i].index); } else break; } if (useVBOs) - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); } void GPU_color_switch(int mode) @@ -1398,8 +1412,8 @@ void *GPU_buffer_lock(GPUBuffer *buffer) return 0; if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id); - varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id); + varray = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); return varray; } else { @@ -1415,10 +1429,10 @@ void *GPU_buffer_lock_stream(GPUBuffer *buffer) return 0; if (useVBOs) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id); + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id); /* discard previous data, avoid stalling gpu */ - glBufferDataARB(GL_ARRAY_BUFFER_ARB, buffer->size, 0, GL_STREAM_DRAW_ARB); - varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + gpu_glBufferData(GL_ARRAY_BUFFER, buffer->size, 0, GL_STREAM_DRAW); + varray = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); return varray; } else { @@ -1432,9 +1446,9 @@ void GPU_buffer_unlock(GPUBuffer *buffer) if (buffer) { /* note: this operation can fail, could return * an error code from this function? */ - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + gpu_glUnmapBuffer(GL_ARRAY_BUFFER); } - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); } } @@ -1609,12 +1623,12 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert, copy_v4_v4(buffers->diffuse_color, diffuse_color); /* Build VBO */ - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); - glBufferDataARB(GL_ARRAY_BUFFER_ARB, + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf); + gpu_glBufferData(GL_ARRAY_BUFFER, sizeof(VertexBufferFormat) * totelem, - NULL, GL_STATIC_DRAW_ARB); + NULL, GL_STATIC_DRAW); - vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + vert_data = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); if (vert_data) { /* Vertex data is shared if smooth-shaded, but separate @@ -1708,14 +1722,14 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert, } } - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + gpu_glUnmapBuffer(GL_ARRAY_BUFFER); } else { - glDeleteBuffersARB(1, &buffers->vert_buf); + gpu_glDeleteBuffers(1, &buffers->vert_buf); buffers->vert_buf = 0; } - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); } buffers->mvert = mvert; @@ -1758,16 +1772,16 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4], * shading requires separate vertex normals so an index buffer is * can't be used there. */ if (gpu_vbo_enabled() && buffers->smooth) - glGenBuffersARB(1, &buffers->index_buf); + gpu_glGenBuffers(1, &buffers->index_buf); if (buffers->index_buf) { /* Generate index buffer object */ - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf); - glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, - sizeof(unsigned short) * tottri * 3, NULL, GL_STATIC_DRAW_ARB); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf); + gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, + sizeof(unsigned short) * tottri * 3, NULL, GL_STATIC_DRAW); /* Fill the triangle buffer */ - tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + tri_data = gpu_glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); if (tri_data) { for (i = 0; i < totface; ++i) { const MFace *f = mface + face_indices[i]; @@ -1791,18 +1805,18 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4], v[2] = 2; } } - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); + gpu_glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); } else { - glDeleteBuffersARB(1, &buffers->index_buf); + gpu_glDeleteBuffers(1, &buffers->index_buf); buffers->index_buf = 0; } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } if (gpu_vbo_enabled() && (buffers->index_buf || !buffers->smooth)) - glGenBuffersARB(1, &buffers->vert_buf); + gpu_glGenBuffers(1, &buffers->vert_buf); buffers->tot_tri = tottri; @@ -1840,11 +1854,11 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, copy_v4_v4(buffers->diffuse_color, diffuse_color); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); - glBufferDataARB(GL_ARRAY_BUFFER_ARB, + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf); + gpu_glBufferData(GL_ARRAY_BUFFER, sizeof(VertexBufferFormat) * totvert, - NULL, GL_STATIC_DRAW_ARB); - vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + NULL, GL_STATIC_DRAW); + vert_data = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); if (vert_data) { for (i = 0; i < totgrid; ++i) { VertexBufferFormat *vd = vert_data; @@ -1905,13 +1919,13 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, vert_data += key->grid_area; } - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + gpu_glUnmapBuffer(GL_ARRAY_BUFFER); } else { - glDeleteBuffersARB(1, &buffers->vert_buf); + gpu_glDeleteBuffers(1, &buffers->vert_buf); buffers->vert_buf = 0; } - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); } buffers->grids = grids; @@ -1933,13 +1947,13 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, int offset = 0; \ int i, j, k; \ \ - glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ + gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, \ sizeof(type_) * (tot_quad_) * 6, NULL, \ - GL_STATIC_DRAW_ARB); \ + GL_STATIC_DRAW); \ \ /* Fill the buffer */ \ - tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \ - GL_WRITE_ONLY_ARB); \ + tri_data = gpu_glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, \ + GL_WRITE_ONLY); \ if (tri_data) { \ for (i = 0; i < totgrid; ++i) { \ BLI_bitmap *gh = NULL; \ @@ -1966,10 +1980,10 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids, \ offset += gridsize * gridsize; \ } \ - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \ + gpu_glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); \ } \ else { \ - glDeleteBuffersARB(1, &(buffer_)); \ + gpu_glDeleteBuffers(1, &(buffer_)); \ (buffer_) = 0; \ } \ } (void)0 @@ -1991,7 +2005,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to * return an invalid handle */ if (!gpu_vbo_enabled()) { if (buffer) - glDeleteBuffersARB(1, &buffer); + gpu_glDeleteBuffers(1, &buffer); return 0; } @@ -2003,11 +2017,11 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to } /* Build new VBO */ - glGenBuffersARB(1, &buffer); + gpu_glGenBuffers(1, &buffer); if (buffer) { *totquad = (gridsize - 1) * (gridsize - 1); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); if (gridsize * gridsize < USHRT_MAX) { *index_type = GL_UNSIGNED_SHORT; @@ -2018,7 +2032,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to FILL_QUAD_BUFFER(unsigned int, *totquad, buffer); } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } prev_gridsize = gridsize; @@ -2054,11 +2068,11 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid, } else if (GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO)) { /* Build new VBO */ - glGenBuffersARB(1, &buffers->index_buf); + gpu_glGenBuffers(1, &buffers->index_buf); if (buffers->index_buf) { buffers->tot_quad = totquad; - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf); if (totgrid * gridsize * gridsize < USHRT_MAX) { buffers->index_type = GL_UNSIGNED_SHORT; @@ -2069,7 +2083,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid, FILL_QUAD_BUFFER(unsigned int, totquad, buffers->index_buf); } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } buffers->has_hidden = 1; @@ -2077,7 +2091,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid, /* Build coord/normal VBO */ if (buffers->index_buf) - glGenBuffersARB(1, &buffers->vert_buf); + gpu_glGenBuffers(1, &buffers->vert_buf); return buffers; } @@ -2209,13 +2223,13 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, copy_v4_v4(buffers->diffuse_color, diffuse_color); /* Initialize vertex buffer */ - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); - glBufferDataARB(GL_ARRAY_BUFFER_ARB, + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf); + gpu_glBufferData(GL_ARRAY_BUFFER, sizeof(VertexBufferFormat) * totvert, - NULL, GL_STATIC_DRAW_ARB); + NULL, GL_STATIC_DRAW); /* Fill vertex buffer */ - vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + vert_data = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); if (vert_data) { int v_index = 0; @@ -2273,14 +2287,14 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, buffers->tot_tri = tottri; } - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + gpu_glUnmapBuffer(GL_ARRAY_BUFFER); /* gpu_bmesh_vert_to_buffer_copy sets dirty index values */ bm->elem_index_dirty |= BM_VERT; } else { /* Memory map failed */ - glDeleteBuffersARB(1, &buffers->vert_buf); + gpu_glDeleteBuffers(1, &buffers->vert_buf); buffers->vert_buf = 0; return; } @@ -2289,15 +2303,15 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, const int use_short = (maxvert < USHRT_MAX); /* Initialize triangle index buffer */ - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf); - glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf); + gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, (use_short ? sizeof(unsigned short) : sizeof(unsigned int)) * 3 * tottri, - NULL, GL_STATIC_DRAW_ARB); + NULL, GL_STATIC_DRAW); /* Fill triangle index buffer */ - tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + tri_data = gpu_glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); if (tri_data) { GSetIterator gs_iter; @@ -2327,7 +2341,7 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, } } - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); + gpu_glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); buffers->tot_tri = tottri; buffers->index_type = (use_short ? @@ -2336,7 +2350,7 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, } else { /* Memory map failed */ - glDeleteBuffersARB(1, &buffers->index_buf); + gpu_glDeleteBuffers(1, &buffers->index_buf); buffers->index_buf = 0; } } @@ -2348,8 +2362,8 @@ GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading) buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers"); if (smooth_shading) - glGenBuffersARB(1, &buffers->index_buf); - glGenBuffersARB(1, &buffers->vert_buf); + gpu_glGenBuffers(1, &buffers->index_buf); + gpu_glGenBuffers(1, &buffers->vert_buf); buffers->use_bmesh = true; buffers->smooth = smooth_shading; buffers->show_diffuse_color = false; @@ -2419,7 +2433,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_PBVH_Buffers *buffers) fmask /= 3.0f; gpu_color_from_mask_set(fmask, diffuse_color); } - + for (j = 0; j < S; j++) glVertex3fv(mvert[fv[j]].co); } @@ -2457,8 +2471,8 @@ static void gpu_draw_buffers_legacy_grids(GPU_PBVH_Buffers *buffers) /* TODO: could use strips with hiding as well */ if (gh) { - glBegin(GL_QUADS); - + glBegin(GL_QUADS); // XXX jwilkins: replace with pairs of triangles + for (y = 0; y < gridsize - 1; y++) { for (x = 0; x < gridsize - 1; x++) { CCGElem *e[4] = { @@ -2504,7 +2518,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_PBVH_Buffers *buffers) } else if (buffers->smooth) { for (y = 0; y < gridsize - 1; y++) { - glBegin(GL_QUAD_STRIP); + glBegin(GL_TRIANGLE_STRIP); // XXX jwilkins: was QUAD_STRIP, only difference should be which vertex is used for flat shading(?) for (x = 0; x < gridsize; x++) { CCGElem *a = CCG_grid_elem(key, grid, x, y); CCGElem *b = CCG_grid_elem(key, grid, x, y + 1); @@ -2525,7 +2539,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_PBVH_Buffers *buffers) } else { for (y = 0; y < gridsize - 1; y++) { - glBegin(GL_QUAD_STRIP); + glBegin(GL_TRIANGLE_STRIP); // XXX jwilkins: was QUAD_STRIP, only difference should be which vertex is used for flat shading(?) for (x = 0; x < gridsize; x++) { CCGElem *a = CCG_grid_elem(key, grid, x, y); CCGElem *b = CCG_grid_elem(key, grid, x, y + 1); @@ -2591,10 +2605,10 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial, gpu_colors_enable(VBO_ENABLED); } - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); + gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf); if (buffers->index_buf) - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf); if (wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -2634,9 +2648,9 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial, if (wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); if (buffers->index_buf) - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisableClientState(GL_VERTEX_ARRAY); if (!wireframe) { @@ -2711,10 +2725,10 @@ static void gpu_pbvh_buffer_free_intern(GLuint id) /* free the buffers immediately if we are on main thread */ if (BLI_thread_is_main()) { - glDeleteBuffersARB(1, &id); + gpu_glDeleteBuffers(1, &id); if (pool->totpbvhbufids > 0) { - glDeleteBuffersARB(pool->totpbvhbufids, pool->pbvhbufids); + gpu_glDeleteBuffers(pool->totpbvhbufids, pool->pbvhbufids); pool->totpbvhbufids = 0; } return; @@ -2797,7 +2811,7 @@ void GPU_init_draw_pbvh_BB(void) glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glEnable(GL_BLEND); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, 0); } void GPU_end_draw_pbvh_BB(void) diff --git a/source/blender/gpu/intern/gpu_clipping.c b/source/blender/gpu/intern/gpu_clipping.c new file mode 100644 index 00000000000..395e661edf8 --- /dev/null +++ b/source/blender/gpu/intern/gpu_clipping.c @@ -0,0 +1,150 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_clipping.c + * \ingroup gpu + */ + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + +/* my interface */ +#include "intern/gpu_clipping_intern.h" + +/* my library */ +//#include "GPU_extensions.h" +#include "GPU_matrix.h" +#include "GPU_safety.h" +#include "GPU_common.h" + +/* internal */ +#include "intern/gpu_common_intern.h" + +/* external */ +#include "BLI_math_vector.h" + + + +static struct CLIPPING { + double clip_plane[GPU_MAX_COMMON_CLIP_PLANES][4]; + uint32_t clip_plane_count; +} CLIPPING; + + + +void gpu_clipping_init(void) +{ + memset(&CLIPPING, 0, sizeof(CLIPPING)); +} + + + +void gpu_clipping_exit(void) +{ +} + + + +void gpu_commit_clipping(void) +{ + const struct GPUcommon* common = gpu_get_common(); + + int i; + + for (i = 0; i < CLIPPING.clip_plane_count; i++) { + if (common) { + glUniform4dv(common->clip_plane[i], 1, CLIPPING.clip_plane[i]); + } + +#if defined(WITH_GL_PROFILE_COMPAT) + if (i < 6) { + glClipPlane(GL_CLIP_PLANE0+i, CLIPPING.clip_plane[i]); // deprecated + } +#endif + } + + if (common) + glUniform1i(common->clip_plane_count, CLIPPING.clip_plane_count); +} + + + +void GPU_restore_clip_planes(int clip_plane_count, const GPUplane clip_planes[]) +{ + GPU_ASSERT(clip_plane_count >= 0); + GPU_ASSERT(clip_plane_count < GPU_MAX_COMMON_CLIP_PLANES); + + memcpy(CLIPPING.clip_plane, clip_planes, clip_plane_count*sizeof(GPUplane)); + + CLIPPING.clip_plane_count = clip_plane_count; +} + + + +static void feedback_clip_plane_position(double position[4] /* in-out */) +{ + GPU_feedback_vertex_4dv(GL_MODELVIEW_MATRIX, position[0], position[1], position[2], position[3], position); +} + + + +void GPU_set_clip_planes(int clip_plane_count, const GPUplane clip_planes[]) +{ + int i; + + GPU_restore_clip_planes(clip_plane_count, clip_planes); + + for (i = 0; i < clip_plane_count; i++) { + feedback_clip_plane_position(CLIPPING.clip_plane[i]); + } +} + + + +int GPU_get_clip_planes(GPUplane clip_planes_out[]) +{ + memcpy(clip_planes_out, CLIPPING.clip_plane, CLIPPING.clip_plane_count*sizeof(GPUplane)); + + return CLIPPING.clip_plane_count; +} + + + +#if defined(WITH_GL_PROFILE_COMPAT) +void gpu_toggle_clipping(bool enable) +{ + unsigned int i; + + for (i = 0; i < CLIPPING.clip_plane_count; i++) { + if (enable) + glEnable (GL_CLIP_PLANE0 + i); // deprecated + else + glDisable(GL_CLIP_PLANE0 + i); // deprecated + } +} +#endif diff --git a/source/blender/gpu/intern/gpu_clipping_intern.h b/source/blender/gpu/intern/gpu_clipping_intern.h new file mode 100644 index 00000000000..ca72ab5c8b3 --- /dev/null +++ b/source/blender/gpu/intern/gpu_clipping_intern.h @@ -0,0 +1,56 @@ +#ifndef _GPU_CLIPPING_INTERN_H_ +#define _GPU_CLIPPING_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2014 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_clipping_intern.h + * \ingroup gpu + */ + +#include "GPU_clipping.h" + +#include "BLI_sys_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_clipping_init(void); +void gpu_clipping_exit(void); + +void gpu_commit_clipping(void); + +#if defined(WITH_GL_PROFILE_COMPAT) +void gpu_toggle_clipping(bool enable); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_CLIP_PLANES_H_ */ diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 6b46db89a93..c9109b96424 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -31,7 +31,16 @@ * Convert material node-trees to GLSL. */ -#include "GL/glew.h" +/* my interface */ +#include "intern/gpu_codegen.h" +/* internal */ +#include "intern/gpu_common_intern.h" + +/* my library */ +#include "GPU_material.h" +#include "GPU_extensions.h" + +/* external */ #include "MEM_guardedalloc.h" @@ -40,29 +49,28 @@ #include "DNA_material_types.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" #include "BLI_dynstr.h" #include "BLI_ghash.h" - -#include "GPU_material.h" -#include "GPU_extensions.h" - -#include "BLI_sys_types.h" // for intptr_t support - -#include "gpu_codegen.h" +#include "BLI_sys_types.h" /* for intptr_t */ +#include "BLI_utildefines.h" #include "node_util.h" /* For muting node stuff... */ +/* standard */ #include <string.h> #include <stdarg.h> -extern char datatoc_gpu_shader_material_glsl[]; -extern char datatoc_gpu_shader_vertex_glsl[]; + + +extern const char datatoc_gpu_shader_material_glsl[]; +extern const char datatoc_gpu_shader_vertex_glsl []; + static char *glsl_material_library = NULL; + /* structs and defines */ static const char *GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4", @@ -242,12 +250,12 @@ GPUFunction *GPU_lookup_function(const char *name) return (GPUFunction*)BLI_ghash_lookup(FUNCTION_HASH, (void *)name); } -void GPU_codegen_init(void) +void gpu_codegen_init(void) { GPU_code_generate_glsl_lib(); } -void GPU_codegen_exit(void) +void gpu_codegen_exit(void) { extern Material defmaterial; // render module abuse... @@ -712,7 +720,6 @@ void GPU_code_generate_glsl_lib(void) BLI_dynstr_append(ds, datatoc_gpu_shader_material_glsl); - glsl_material_library = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); @@ -1406,7 +1413,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri /* generate code and compile with opengl */ fragmentcode = code_generate_fragment(nodes, outlink->output, name); vertexcode = code_generate_vertex(nodes); - shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library, NULL); + shader = GPU_shader_create(__func__, vertexcode, fragmentcode, glsl_material_library, NULL); /* failed? */ if (!shader) { @@ -1421,7 +1428,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri } /* create pass */ - pass = MEM_callocN(sizeof(GPUPass), "GPUPass"); + pass = (GPUPass*)MEM_callocN(sizeof(GPUPass), __func__); pass->output = outlink->output; pass->shader = shader; diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h index b6db923e5c2..8dbe648281c 100644 --- a/source/blender/gpu/intern/gpu_codegen.h +++ b/source/blender/gpu/intern/gpu_codegen.h @@ -33,17 +33,11 @@ #ifndef __GPU_CODEGEN_H__ #define __GPU_CODEGEN_H__ -#include "DNA_listBase.h" #include "GPU_material.h" -#include "GL/glew.h" -struct ListBase; +#include "DNA_listBase.h" + struct GPUShader; -struct GPUOutput; -struct GPUNode; -struct GPUVertexAttribs; -struct GPUFrameBuffer; -struct PreviewImage; #define MAX_FUNCTION_NAME 64 #define MAX_PARAMETER 32 @@ -87,7 +81,7 @@ struct GPUNode { }; struct GPUNodeLink { - GPUNodeStack *socket; + struct GPUNodeStack *socket; int attribtype; const char *attribname; @@ -106,7 +100,7 @@ struct GPUNodeLink { int type; int users; - GPUTexture *dynamictex; + struct GPUTexture *dynamictex; GPUBuiltin builtin; GPUOpenGLBuiltin oglbuiltin; @@ -117,16 +111,16 @@ struct GPUNodeLink { typedef struct GPUOutput { struct GPUOutput *next, *prev; - GPUNode *node; + struct GPUNode *node; int type; /* data type = length of vector/matrix */ - GPUNodeLink *link; /* output link */ + struct GPUNodeLink *link; /* output link */ int id; /* unique id as created by code generator */ } GPUOutput; typedef struct GPUInput { struct GPUInput *next, *prev; - GPUNode *node; + struct GPUNode *node; int type; /* datatype */ int source; /* data source */ @@ -136,7 +130,7 @@ typedef struct GPUInput { int attribid; /* id for vertex attributes */ int bindtex; /* input is responsible for binding the texture? */ int definetex; /* input is responsible for defining the pixel? */ - int textarget; /* GL_TEXTURE_* */ + int textarget; /* GL texture enum */ int textype; /* datatype */ struct Image *ima; /* image */ @@ -146,17 +140,17 @@ typedef struct GPUInput { float *dynamicvec; /* vector data in case it is dynamic */ int dynamictype; /* origin of the dynamic uniform (GPUDynamicType) */ void *dynamicdata; /* data source of the dynamic uniform */ - GPUTexture *tex; /* input texture, only set at runtime */ + struct GPUTexture *tex; /* input texture, only set at runtime */ int shaderloc; /* id from opengl */ char shadername[32]; /* name in shader */ float vec[16]; /* vector data */ - GPUNodeLink *link; + struct GPUNodeLink *link; int dynamictex; /* dynamic? */ int attribtype; /* attribute type */ char attribname[32]; /* attribute name */ int attribfirst; /* this is the first one that is bound */ - GPUBuiltin builtin; /* builtin uniform */ + GPUBuiltin builtin; /* builtin uniform */ GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */ } GPUInput; @@ -185,8 +179,8 @@ void GPU_pass_unbind(GPUPass *pass); void GPU_pass_free(GPUPass *pass); -void GPU_codegen_init(void); -void GPU_codegen_exit(void); +void gpu_codegen_init(void); +void gpu_codegen_exit(void); /* Material calls */ diff --git a/source/blender/gpu/intern/gpu_common.c b/source/blender/gpu/intern/gpu_common.c new file mode 100644 index 00000000000..338c5eee133 --- /dev/null +++ b/source/blender/gpu/intern/gpu_common.c @@ -0,0 +1,503 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_common.c + * \ingroup gpu + */ + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + +/* my interface */ +#include "intern/gpu_common_intern.h" + +/* my library */ +#include "GPU_extensions.h" +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_extensions_intern.h" +#include "intern/gpu_profile.h" + +#if WITH_GL_PROFILE_COMPAT +#include "intern/gpu_immediate_intern.h" +#endif + +/* external */ +#include "BLI_dynstr.h" +#include "BLI_utildefines.h" + +/* standard */ +#include <stdio.h> +#include <string.h> + + + +extern const char datatoc_gpu_shader_common_constants_glsl[]; +extern const char datatoc_gpu_shader_common_uniforms_glsl []; +extern const char datatoc_gpu_shader_common_attribs_glsl []; + + + +static GPUcommon* current_common = NULL; +static GLint active_texture_num = 0; + + + +void gpu_include_common_vert(DynStr* vert) +{ + BLI_dynstr_append(vert, datatoc_gpu_shader_common_constants_glsl); + BLI_dynstr_append(vert, datatoc_gpu_shader_common_uniforms_glsl); + BLI_dynstr_append(vert, datatoc_gpu_shader_common_attribs_glsl); +} + + + +void gpu_include_common_frag(DynStr* frag) +{ + BLI_dynstr_append(frag, datatoc_gpu_shader_common_constants_glsl); + BLI_dynstr_append(frag, datatoc_gpu_shader_common_uniforms_glsl); +} + + + +void gpu_include_common_defs(DynStr* defs) +{ + BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_TEXCOORDS " STRINGIFY(GPU_MAX_COMMON_TEXCOORDS ) "\n"); + BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_SAMPLERS " STRINGIFY(GPU_MAX_COMMON_SAMPLERS ) "\n"); + BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_LIGHTS " STRINGIFY(GPU_MAX_COMMON_LIGHTS ) "\n"); + BLI_dynstr_append(defs, "#define GPU_MAX_COMMON_CLIP_PLANES " STRINGIFY(GPU_MAX_COMMON_CLIP_PLANES) "\n"); + + if (GPU_PROFILE_COMPAT) + BLI_dynstr_append(defs, "#define GPU_PROFILE_COMPAT\n"); + + if (GPU_PROFILE_CORE) + BLI_dynstr_append(defs, "#define GPU_PROFILE_CORE\n"); + + if (GPU_PROFILE_ES20) + BLI_dynstr_append(defs, "#define GPU_PROFILE_ES20\n"); +} + + + +static void get_struct_uniform(GLint* out, GPUShader* gpushader, char symbol[], size_t len, const char* field) +{ + symbol[len] = '\0'; + strcat(symbol, field); + *out = GPU_shader_get_uniform(gpushader, symbol); +} + + + +void gpu_common_get_symbols(GPUcommon* common, GPUShader* gpushader) +{ + int i; + + /* Attributes */ + common->vertex = GPU_shader_get_attribute(gpushader, "b_Vertex"); + common->color = GPU_shader_get_attribute(gpushader, "b_Color"); + common->normal = GPU_shader_get_attribute(gpushader, "b_Normal"); + + /* Transformation */ + common->modelview_matrix = GPU_shader_get_uniform(gpushader, "b_ModelViewMatrix"); + common->modelview_projection_matrix = GPU_shader_get_uniform(gpushader, "b_ModelViewProjectionMatrix"); + common->modelview_matrix_inverse = GPU_shader_get_uniform(gpushader, "b_ModelViewMatrixInverse"); + common->projection_matrix = GPU_shader_get_uniform(gpushader, "b_ProjectionMatrix"); + + /* Texture Mapping */ + + for (i = 0; i < GPU_MAX_COMMON_TEXCOORDS; i++) { + char symbol[100]; + + sprintf(symbol, "b_MultiTexCoord%d", i); + common->multi_texcoord[i] = GPU_shader_get_attribute(gpushader, symbol); + + sprintf(symbol, "b_TextureMatrix[%d]", i); + common->texture_matrix[i] = GPU_shader_get_uniform(gpushader, symbol); + } + + for (i = 0; i < GPU_MAX_COMMON_SAMPLERS; i++) { + char symbol[100]; + + sprintf(symbol, "b_Sampler2D[%d]", i); + common->sampler[i] = GPU_shader_get_uniform(gpushader, symbol); + } + + /* Lighting */ + + /* Lights */ + for (i = 0; i < GPU_MAX_COMMON_LIGHTS; i++) { + char symbol[100]; + int len; + + len = sprintf(symbol, "b_LightSource[%d]", i); + + get_struct_uniform(common->light_position + i, gpushader, symbol, len, ".position"); + get_struct_uniform(common->light_diffuse + i, gpushader, symbol, len, ".diffuse"); + get_struct_uniform(common->light_specular + i, gpushader, symbol, len, ".specular"); + + get_struct_uniform(common->light_constant_attenuation + i, gpushader, symbol, len, ".constantAttenuation"); + get_struct_uniform(common->light_linear_attenuation + i, gpushader, symbol, len, ".linearAttenuation"); + get_struct_uniform(common->light_quadratic_attenuation + i, gpushader, symbol, len, ".quadraticAttenuation"); + + get_struct_uniform(common->light_spot_direction + i, gpushader, symbol, len, ".spotDirection"); + get_struct_uniform(common->light_spot_cutoff + i, gpushader, symbol, len, ".spotCutoff"); + get_struct_uniform(common->light_spot_cos_cutoff + i, gpushader, symbol, len, ".spotCosCutoff"); + get_struct_uniform(common->light_spot_exponent + i, gpushader, symbol, len, ".spotExponent"); + } + + common->normal_matrix = GPU_shader_get_uniform(gpushader, "b_NormalMatrix"); + common->light_count = GPU_shader_get_uniform(gpushader, "b_LightCount"); + + /* Material */ + common->material_specular = GPU_shader_get_uniform(gpushader, "b_FrontMaterial.specular"); + common->material_shininess = GPU_shader_get_uniform(gpushader, "b_FrontMaterial.shininess"); + + /* Clip Planes */ + + for (i = 0; i < GPU_MAX_COMMON_CLIP_PLANES; i++) { + char symbol[100]; + + sprintf(symbol, "b_ClipPlane[%d]", i); + common->clip_plane[i] = GPU_shader_get_uniform(gpushader, symbol); + } + + common->clip_plane_count = GPU_shader_get_uniform(gpushader, "b_ClipPlaneCount"); +} + + + +void gpu_common_init(void) +{ + current_common = NULL; +} + + + +void gpu_common_exit(void) +{ +} + + + +void gpu_set_common(GPUcommon* common) +{ + current_common = common; +} + + + +GPUcommon* gpu_get_common(void) +{ + return current_common; +} + + + +void GPU_common_enable_vertex_array (void) +{ + if (current_common != NULL) { + if (current_common->vertex != -1) + GPU_CHECK(gpu_glEnableVertexAttribArray(current_common->vertex)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glEnableClientState(GL_VERTEX_ARRAY)); +#endif +} + + + +void GPU_common_enable_normal_array (void) +{ + if (current_common != NULL) { + if (current_common->normal != -1) + GPU_CHECK(gpu_glEnableVertexAttribArray(current_common->normal)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glEnableClientState(GL_NORMAL_ARRAY)); +#endif +} + + + +void GPU_common_enable_color_array (void) +{ + if (current_common != NULL) { + if (current_common->color != -1) + GPU_CHECK(gpu_glEnableVertexAttribArray(current_common->color)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glEnableClientState(GL_COLOR_ARRAY)); +#endif +} + + + +void GPU_common_enable_texcoord_array (void) +{ + GPU_ASSERT(active_texture_num >= 0); + GPU_ASSERT(active_texture_num < GPU_MAX_COMMON_TEXCOORDS); + + if (current_common != NULL) { + if (current_common->multi_texcoord[active_texture_num] != -1) + GPU_CHECK(gpu_glEnableVertexAttribArray(current_common->multi_texcoord[active_texture_num])); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + if (active_texture_num < GPU_max_textures()) + GPU_CHECK(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); +#endif +} + + + +void GPU_common_disable_vertex_array (void) +{ + if (current_common != NULL) { + if (current_common->vertex != -1) + GPU_CHECK(gpu_glDisableVertexAttribArray(current_common->vertex)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glDisableClientState(GL_VERTEX_ARRAY)); +#endif +} + + + +void GPU_common_disable_normal_array (void) +{ + if (current_common != NULL) { + if (current_common->normal != -1) + GPU_CHECK(gpu_glDisableVertexAttribArray(current_common->normal)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glDisableClientState(GL_NORMAL_ARRAY)); +#endif +} + + + +void GPU_common_disable_color_array (void) +{ + if (current_common != NULL) { + if (current_common->color != -1) + GPU_CHECK(gpu_glDisableVertexAttribArray(current_common->color)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glDisableClientState(GL_COLOR_ARRAY)); +#endif +} + + + +void GPU_common_disable_texcoord_array(void) +{ + GPU_ASSERT(active_texture_num >= 0); + GPU_ASSERT(active_texture_num < GPU_MAX_COMMON_TEXCOORDS); + + if (current_common != NULL) { + if (current_common->multi_texcoord[active_texture_num] != -1) + GPU_CHECK(gpu_glDisableVertexAttribArray(current_common->multi_texcoord[active_texture_num])); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glDisableClientState(GL_TEXTURE_COORD_ARRAY)); +#endif +} + + + +void GPU_common_vertex_pointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) +{ + if (current_common != NULL) { + if (current_common->vertex != -1) + GPU_CHECK(gpu_glVertexAttribPointer(current_common->vertex, size, type, GL_FALSE, stride, pointer)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glVertexPointer(size, type, stride, pointer)); +#endif +} + + + +void GPU_common_normal_pointer(GLenum type, GLsizei stride, GLboolean normalized, const GLvoid* pointer) +{ + if (current_common != NULL) { + if (current_common->normal != -1) + GPU_CHECK(gpu_glVertexAttribPointer(current_common->normal, 3, type, normalized, stride, pointer)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glNormalPointer(type, stride, pointer)); +#endif +} + + + +void GPU_common_color_pointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) +{ + GPU_ASSERT(type == GL_UNSIGNED_BYTE); // making assumptions about the type being a fixed point type + + if (current_common != NULL) { + if (current_common->color != -1) + GPU_CHECK(gpu_glVertexAttribPointer(current_common->color, size, type, GL_TRUE, stride, pointer)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glColorPointer(size, type, stride, pointer)); +#endif +} + + + +void GPU_common_texcoord_pointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) +{ + GPU_ASSERT(active_texture_num >= 0); + GPU_ASSERT(active_texture_num < GPU_MAX_COMMON_TEXCOORDS); + + if (current_common != NULL) { + if (current_common->multi_texcoord[active_texture_num] != -1) + GPU_CHECK(gpu_glVertexAttribPointer(current_common->multi_texcoord[active_texture_num], size, type, GL_FALSE, stride, pointer)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + if (active_texture_num < GPU_max_textures()) + GPU_CHECK(glTexCoordPointer(size, type, stride, pointer)); +#endif +} + + + +void GPU_set_common_active_texture(GLint texture) +{ + GLint texture_num = texture; + + GPU_ASSERT(texture_num >= 0); + GPU_ASSERT(texture_num < GPU_MAX_COMMON_TEXCOORDS); + + if (texture_num >= 0 && texture_num < GPU_MAX_COMMON_TEXCOORDS) + active_texture_num = texture_num; + +#if defined(WITH_GL_PROFILE_COMPAT) + if (active_texture_num < GPU_max_textures()) + GPU_CHECK(glClientActiveTexture(GL_TEXTURE0+texture)); +#endif +} + + + +GLint GPU_get_common_active_texture(void) +{ + return active_texture_num; +} + + + +void GPU_common_normal_3fv(GLfloat n[3]) +{ + if (current_common != NULL) { + if (current_common->normal != -1) + GPU_CHECK(glVertexAttrib3fv(current_common->normal, n)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glNormal3fv(GPU_IMMEDIATE->normal)); // deprecated +#endif +} + + + +void GPU_common_color_4ubv(GLubyte c[4]) +{ + if (current_common != NULL) { + if (current_common->color != -1) { + GPU_CHECK( + glVertexAttrib4f( + current_common->color, + ((float)(c[0]))/255.0f, + ((float)(c[1]))/255.0f, + ((float)(c[2]))/255.0f, + ((float)(c[3]))/255.0f)); + } + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glColor4ubv(c)); // deprecated +#endif +} + + + +void GPU_common_color_4fv(GLfloat c[4]) +{ + if (current_common != NULL) { + if (current_common->color != -1) + GPU_CHECK(glVertexAttrib4fv(current_common->color, c)); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + GPU_CHECK(glColor4fv(c)); // deprecated +#endif +} diff --git a/source/blender/gpu/intern/gpu_common_intern.h b/source/blender/gpu/intern/gpu_common_intern.h new file mode 100644 index 00000000000..3f42c491ccf --- /dev/null +++ b/source/blender/gpu/intern/gpu_common_intern.h @@ -0,0 +1,142 @@ +#ifndef _GPU_COMMON_INTERN_H_ +#define _GPU_COMMON_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_common_intern.h + * \ingroup gpu + */ + +#include "GPU_common.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +struct DynStr; + + + +/* GPUShader */ + +struct GPUShader { + GLuint object; /* handle for full shader */ + GLuint vertex; /* handle for vertex shader */ + GLuint fragment; /* handle for fragment shader */ + GLuint lib; /* handle for library shader */ + int totattrib; /* total number of attributes */ +}; + + + +/* + +The 'common' module defines a set of +well-known or "common" GLSL variable names. + +These common names serve as an interface for +writing shaders that work with Blender's draw routines. + +The 'basic', 'font', and 'codegen' shaders are +written using these variable names. + +All of Blender's drawing routines generate uniforms and +attributes that are mapped to these names. + +Any rarely used or uncommon attributes and uniforms needed for +advanced drawing routines do not belong here! + +*/ + +typedef struct GPUcommon { + GLint vertex; /* b_Vertex */ + GLint color; /* b_Color */ + GLint normal; /* b_Normal */ + + GLint modelview_matrix; /* b_ModelViewMatrix */ + GLint modelview_matrix_inverse; /* b_ModelViewMatrixInverse */ + GLint modelview_projection_matrix; /* b_ModelViewProjectionMatrix */ + GLint projection_matrix; /* b_ProjectionMatrix */ + + GLint multi_texcoord[GPU_MAX_COMMON_TEXCOORDS]; /* b_MultiTexCoord[] */ + GLint texture_matrix[GPU_MAX_COMMON_TEXCOORDS]; /* b_TextureMatrix[] */ + + GLint sampler[GPU_MAX_COMMON_SAMPLERS]; /* b_Sampler[] */ + + GLint light_position [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].position */ + GLint light_diffuse [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].diffuse */ + GLint light_specular [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].specular */ + + GLint light_constant_attenuation [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].constantAttenuation */ + GLint light_linear_attenuation [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].linearAttenuation */ + GLint light_quadratic_attenuation[GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].quadraticAttenuation */ + + GLint light_spot_direction [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].spotDirection */ + GLint light_spot_cutoff [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].spotCutoff */ + GLint light_spot_cos_cutoff [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].spotCusCutoff */ + GLint light_spot_exponent [GPU_MAX_COMMON_LIGHTS]; /* b_LightSource[].spotExponent */ + + GLint normal_matrix; /* b_NormalMatrix */ + + GLint light_count; /* b_LightCount */ + + GLint material_specular; /* b_FrontMaterial.specular */ + GLint material_shininess; /* b_FrontMaterial.shininess */ + + GLint clip_plane[6]; /* b_ClipPlane[] */ + GLint clip_plane_count; /* b_ClipPlaneCount */ +} GPUcommon; + + + +void gpu_common_init(void); +void gpu_common_exit(void); + +/* given a GPUShader, initialize a GPUcommon */ +void gpu_common_get_symbols(GPUcommon* common, struct GPUShader* gpushader); + +/* set/get the global GPUcommon currently in use */ +void gpu_set_common(GPUcommon* common); +GPUcommon* gpu_get_common(void); + +/* for appending GLSL code that defines the common interface */ +void gpu_include_common_vert(struct DynStr* vert); +void gpu_include_common_frag(struct DynStr* frag); +void gpu_include_common_defs(struct DynStr* defs); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_COMMON_H_ */ diff --git a/source/blender/gpu/intern/gpu_debug.c b/source/blender/gpu/intern/gpu_debug.c new file mode 100644 index 00000000000..1378bb96b1d --- /dev/null +++ b/source/blender/gpu/intern/gpu_debug.c @@ -0,0 +1,428 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Brecht Van Lommel. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_debug.c + * \ingroup gpu + */ + +#ifdef DEBUG + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + +#include "GPU_draw.h" + +#include <stdio.h> +#include <string.h> + +/* debugging aid */ +static void gpu_state_print_fl_ex(const char *name, GLenum type) +{ + const unsigned char err_mark[4] = {0xff, 0xff, 0xff, 0xff}; + + float value[32]; + int a; + + memset(value, 0xff, sizeof(value)); + glGetFloatv(type, value); + + printf("%s: ", name); + for (a = 0; a < 32; a++) { + if (memcmp(&value[a], err_mark, sizeof(value[a])) == 0) { + break; + } + printf("%.2f ", value[a]); + } + printf("\n"); +} + +#define gpu_state_print_fl(val) gpu_state_print_fl_ex(#val, val) + +void GPU_state_print(void) +{ + gpu_state_print_fl(GL_ACCUM_ALPHA_BITS); + gpu_state_print_fl(GL_ACCUM_BLUE_BITS); + gpu_state_print_fl(GL_ACCUM_CLEAR_VALUE); + gpu_state_print_fl(GL_ACCUM_GREEN_BITS); + gpu_state_print_fl(GL_ACCUM_RED_BITS); + gpu_state_print_fl(GL_ACTIVE_TEXTURE); + gpu_state_print_fl(GL_ALIASED_LINE_WIDTH_RANGE); + gpu_state_print_fl(GL_ALIASED_POINT_SIZE_RANGE); + gpu_state_print_fl(GL_ALPHA_BIAS); + gpu_state_print_fl(GL_ALPHA_BITS); + gpu_state_print_fl(GL_ALPHA_SCALE); + gpu_state_print_fl(GL_ALPHA_TEST); + gpu_state_print_fl(GL_ALPHA_TEST_FUNC); + gpu_state_print_fl(GL_ALPHA_TEST_REF); + gpu_state_print_fl(GL_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_ATTRIB_STACK_DEPTH); + gpu_state_print_fl(GL_AUTO_NORMAL); + gpu_state_print_fl(GL_AUX_BUFFERS); + gpu_state_print_fl(GL_BLEND); + gpu_state_print_fl(GL_BLEND_COLOR); + gpu_state_print_fl(GL_BLEND_DST_ALPHA); + gpu_state_print_fl(GL_BLEND_DST_RGB); + gpu_state_print_fl(GL_BLEND_EQUATION_ALPHA); + gpu_state_print_fl(GL_BLEND_EQUATION_RGB); + gpu_state_print_fl(GL_BLEND_SRC_ALPHA); + gpu_state_print_fl(GL_BLEND_SRC_RGB); + gpu_state_print_fl(GL_BLUE_BIAS); + gpu_state_print_fl(GL_BLUE_BITS); + gpu_state_print_fl(GL_BLUE_SCALE); + gpu_state_print_fl(GL_CLIENT_ACTIVE_TEXTURE); + gpu_state_print_fl(GL_CLIENT_ATTRIB_STACK_DEPTH); + gpu_state_print_fl(GL_CLIP_PLANE0); + gpu_state_print_fl(GL_COLOR_ARRAY); + gpu_state_print_fl(GL_COLOR_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_COLOR_ARRAY_SIZE); + gpu_state_print_fl(GL_COLOR_ARRAY_STRIDE); + gpu_state_print_fl(GL_COLOR_ARRAY_TYPE); + gpu_state_print_fl(GL_COLOR_CLEAR_VALUE); + gpu_state_print_fl(GL_COLOR_LOGIC_OP); + gpu_state_print_fl(GL_COLOR_MATERIAL); + gpu_state_print_fl(GL_COLOR_MATERIAL_FACE); + gpu_state_print_fl(GL_COLOR_MATERIAL_PARAMETER); + gpu_state_print_fl(GL_COLOR_MATRIX); + gpu_state_print_fl(GL_COLOR_MATRIX_STACK_DEPTH); + gpu_state_print_fl(GL_COLOR_SUM); + gpu_state_print_fl(GL_COLOR_TABLE); + gpu_state_print_fl(GL_COLOR_WRITEMASK); + gpu_state_print_fl(GL_COMPRESSED_TEXTURE_FORMATS); + gpu_state_print_fl(GL_CONVOLUTION_1D); + gpu_state_print_fl(GL_CONVOLUTION_2D); + gpu_state_print_fl(GL_CULL_FACE); + gpu_state_print_fl(GL_CULL_FACE_MODE); + gpu_state_print_fl(GL_CURRENT_COLOR); + gpu_state_print_fl(GL_CURRENT_FOG_COORD); + gpu_state_print_fl(GL_CURRENT_INDEX); + gpu_state_print_fl(GL_CURRENT_NORMAL); + gpu_state_print_fl(GL_CURRENT_PROGRAM); + gpu_state_print_fl(GL_CURRENT_RASTER_COLOR); + gpu_state_print_fl(GL_CURRENT_RASTER_DISTANCE); + gpu_state_print_fl(GL_CURRENT_RASTER_INDEX); + gpu_state_print_fl(GL_CURRENT_RASTER_POSITION); + gpu_state_print_fl(GL_CURRENT_RASTER_POSITION_VALID); + gpu_state_print_fl(GL_CURRENT_RASTER_SECONDARY_COLOR); + gpu_state_print_fl(GL_CURRENT_RASTER_TEXTURE_COORDS); + gpu_state_print_fl(GL_CURRENT_SECONDARY_COLOR); + gpu_state_print_fl(GL_CURRENT_TEXTURE_COORDS); + gpu_state_print_fl(GL_DEPTH_BIAS); + gpu_state_print_fl(GL_DEPTH_BITS); + gpu_state_print_fl(GL_DEPTH_CLEAR_VALUE); + gpu_state_print_fl(GL_DEPTH_FUNC); + gpu_state_print_fl(GL_DEPTH_RANGE); + gpu_state_print_fl(GL_DEPTH_SCALE); + gpu_state_print_fl(GL_DEPTH_TEST); + gpu_state_print_fl(GL_DEPTH_WRITEMASK); + gpu_state_print_fl(GL_DITHER); + gpu_state_print_fl(GL_DOUBLEBUFFER); + gpu_state_print_fl(GL_DRAW_BUFFER); + gpu_state_print_fl(GL_DRAW_BUFFER0); + gpu_state_print_fl(GL_EDGE_FLAG); + gpu_state_print_fl(GL_EDGE_FLAG_ARRAY); + gpu_state_print_fl(GL_EDGE_FLAG_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_EDGE_FLAG_ARRAY_STRIDE); + gpu_state_print_fl(GL_ELEMENT_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_FEEDBACK_BUFFER_SIZE); + gpu_state_print_fl(GL_FEEDBACK_BUFFER_TYPE); + gpu_state_print_fl(GL_FOG); + gpu_state_print_fl(GL_FOG_COLOR); + gpu_state_print_fl(GL_FOG_COORD_ARRAY); + gpu_state_print_fl(GL_FOG_COORD_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_FOG_COORD_ARRAY_STRIDE); + gpu_state_print_fl(GL_FOG_COORD_ARRAY_TYPE); + gpu_state_print_fl(GL_FOG_COORD_SRC); + gpu_state_print_fl(GL_FOG_DENSITY); + gpu_state_print_fl(GL_FOG_END); + gpu_state_print_fl(GL_FOG_HINT); + gpu_state_print_fl(GL_FOG_INDEX); + gpu_state_print_fl(GL_FOG_MODE); + gpu_state_print_fl(GL_FOG_START); + gpu_state_print_fl(GL_FRAGMENT_PROGRAM_ARB); + gpu_state_print_fl(GL_FRAGMENT_SHADER_DERIVATIVE_HINT); + gpu_state_print_fl(GL_FRONT_FACE); + gpu_state_print_fl(GL_GENERATE_MIPMAP_HINT); + gpu_state_print_fl(GL_GREEN_BIAS); + gpu_state_print_fl(GL_GREEN_BITS); + gpu_state_print_fl(GL_GREEN_SCALE); + gpu_state_print_fl(GL_HISTOGRAM); + gpu_state_print_fl(GL_INDEX_ARRAY); + gpu_state_print_fl(GL_INDEX_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_INDEX_ARRAY_STRIDE); + gpu_state_print_fl(GL_INDEX_ARRAY_TYPE); + gpu_state_print_fl(GL_INDEX_BITS); + gpu_state_print_fl(GL_INDEX_CLEAR_VALUE); + gpu_state_print_fl(GL_INDEX_LOGIC_OP); + gpu_state_print_fl(GL_INDEX_MODE); + gpu_state_print_fl(GL_INDEX_OFFSET); + gpu_state_print_fl(GL_INDEX_SHIFT); + gpu_state_print_fl(GL_INDEX_WRITEMASK); + gpu_state_print_fl(GL_LIGHT0); + gpu_state_print_fl(GL_LIGHT1); + gpu_state_print_fl(GL_LIGHT2); + gpu_state_print_fl(GL_LIGHT3); + gpu_state_print_fl(GL_LIGHT4); + gpu_state_print_fl(GL_LIGHT5); + gpu_state_print_fl(GL_LIGHT6); + gpu_state_print_fl(GL_LIGHT7); + gpu_state_print_fl(GL_LIGHTING); + gpu_state_print_fl(GL_LIGHT_MODEL_AMBIENT); + gpu_state_print_fl(GL_LIGHT_MODEL_COLOR_CONTROL); + gpu_state_print_fl(GL_LIGHT_MODEL_LOCAL_VIEWER); + gpu_state_print_fl(GL_LIGHT_MODEL_TWO_SIDE); + gpu_state_print_fl(GL_LINE_SMOOTH); + gpu_state_print_fl(GL_LINE_SMOOTH_HINT); + gpu_state_print_fl(GL_LINE_STIPPLE); + gpu_state_print_fl(GL_LINE_STIPPLE_PATTERN); + gpu_state_print_fl(GL_LINE_STIPPLE_REPEAT); + gpu_state_print_fl(GL_LINE_WIDTH); + gpu_state_print_fl(GL_LINE_WIDTH_GRANULARITY); + gpu_state_print_fl(GL_LINE_WIDTH_RANGE); + gpu_state_print_fl(GL_LIST_BASE); + gpu_state_print_fl(GL_LIST_INDEX); + gpu_state_print_fl(GL_LIST_MODE); + gpu_state_print_fl(GL_LOGIC_OP); + gpu_state_print_fl(GL_LOGIC_OP_MODE); + gpu_state_print_fl(GL_MAP1_COLOR_4); + gpu_state_print_fl(GL_MAP1_GRID_DOMAIN); + gpu_state_print_fl(GL_MAP1_GRID_SEGMENTS); + gpu_state_print_fl(GL_MAP1_INDEX); + gpu_state_print_fl(GL_MAP1_NORMAL); + gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_1); + gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_2); + gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_3); + gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_4); + gpu_state_print_fl(GL_MAP1_VERTEX_3); + gpu_state_print_fl(GL_MAP1_VERTEX_4); + gpu_state_print_fl(GL_MAP2_COLOR_4); + gpu_state_print_fl(GL_MAP2_GRID_DOMAIN); + gpu_state_print_fl(GL_MAP2_GRID_SEGMENTS); + gpu_state_print_fl(GL_MAP2_INDEX); + gpu_state_print_fl(GL_MAP2_NORMAL); + gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_1); + gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_2); + gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_3); + gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_4); + gpu_state_print_fl(GL_MAP2_VERTEX_3); + gpu_state_print_fl(GL_MAP2_VERTEX_4); + gpu_state_print_fl(GL_MAP_COLOR); + gpu_state_print_fl(GL_MAP_STENCIL); + gpu_state_print_fl(GL_MATRIX_MODE); + gpu_state_print_fl(GL_MAX_3D_TEXTURE_SIZE); + gpu_state_print_fl(GL_MAX_ATTRIB_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_CLIENT_ATTRIB_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_CLIP_PLANES); + gpu_state_print_fl(GL_MAX_COLOR_MATRIX_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS); + gpu_state_print_fl(GL_MAX_CUBE_MAP_TEXTURE_SIZE); + gpu_state_print_fl(GL_MAX_DRAW_BUFFERS); + gpu_state_print_fl(GL_MAX_ELEMENTS_INDICES); + gpu_state_print_fl(GL_MAX_ELEMENTS_VERTICES); + gpu_state_print_fl(GL_MAX_EVAL_ORDER); + gpu_state_print_fl(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS); + gpu_state_print_fl(GL_MAX_LIGHTS); + gpu_state_print_fl(GL_MAX_LIST_NESTING); + gpu_state_print_fl(GL_MAX_MODELVIEW_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_NAME_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_PIXEL_MAP_TABLE); + gpu_state_print_fl(GL_MAX_PROJECTION_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_TEXTURE_COORDS); + gpu_state_print_fl(GL_MAX_TEXTURE_IMAGE_UNITS); + gpu_state_print_fl(GL_MAX_TEXTURE_LOD_BIAS); + gpu_state_print_fl(GL_MAX_TEXTURE_SIZE); + gpu_state_print_fl(GL_MAX_TEXTURE_STACK_DEPTH); + gpu_state_print_fl(GL_MAX_TEXTURE_UNITS); + gpu_state_print_fl(GL_MAX_VARYING_FLOATS); + gpu_state_print_fl(GL_MAX_VERTEX_ATTRIBS); + gpu_state_print_fl(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS); + gpu_state_print_fl(GL_MAX_VERTEX_UNIFORM_COMPONENTS); + gpu_state_print_fl(GL_MAX_VIEWPORT_DIMS); + gpu_state_print_fl(GL_MINMAX); + gpu_state_print_fl(GL_MODELVIEW_MATRIX); + gpu_state_print_fl(GL_MODELVIEW_STACK_DEPTH); + gpu_state_print_fl(GL_MULTISAMPLE); + gpu_state_print_fl(GL_MULTISAMPLE_ARB); + gpu_state_print_fl(GL_NAME_STACK_DEPTH); + gpu_state_print_fl(GL_NORMALIZE); + gpu_state_print_fl(GL_NORMAL_ARRAY); + gpu_state_print_fl(GL_NORMAL_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_NORMAL_ARRAY_STRIDE); + gpu_state_print_fl(GL_NORMAL_ARRAY_TYPE); + gpu_state_print_fl(GL_NUM_COMPRESSED_TEXTURE_FORMATS); + gpu_state_print_fl(GL_PACK_ALIGNMENT); + gpu_state_print_fl(GL_PACK_IMAGE_HEIGHT); + gpu_state_print_fl(GL_PACK_LSB_FIRST); + gpu_state_print_fl(GL_PACK_ROW_LENGTH); + gpu_state_print_fl(GL_PACK_SKIP_IMAGES); + gpu_state_print_fl(GL_PACK_SKIP_PIXELS); + gpu_state_print_fl(GL_PACK_SKIP_ROWS); + gpu_state_print_fl(GL_PACK_SWAP_BYTES); + gpu_state_print_fl(GL_PERSPECTIVE_CORRECTION_HINT); + gpu_state_print_fl(GL_PIXEL_MAP_A_TO_A_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_B_TO_B_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_G_TO_G_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_I_TO_A_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_I_TO_B_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_I_TO_G_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_I_TO_I_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_I_TO_R_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_R_TO_R_SIZE); + gpu_state_print_fl(GL_PIXEL_MAP_S_TO_S_SIZE); + gpu_state_print_fl(GL_PIXEL_PACK_BUFFER_BINDING); + gpu_state_print_fl(GL_PIXEL_UNPACK_BUFFER_BINDING); + gpu_state_print_fl(GL_POINT_DISTANCE_ATTENUATION); + gpu_state_print_fl(GL_POINT_FADE_THRESHOLD_SIZE); + gpu_state_print_fl(GL_POINT_SIZE); + gpu_state_print_fl(GL_POINT_SIZE_GRANULARITY); + gpu_state_print_fl(GL_POINT_SIZE_MAX); + gpu_state_print_fl(GL_POINT_SIZE_MIN); + gpu_state_print_fl(GL_POINT_SIZE_RANGE); + gpu_state_print_fl(GL_POINT_SMOOTH); + gpu_state_print_fl(GL_POINT_SMOOTH_HINT); + gpu_state_print_fl(GL_POINT_SPRITE); + gpu_state_print_fl(GL_POLYGON_MODE); + gpu_state_print_fl(GL_POLYGON_OFFSET_FACTOR); + gpu_state_print_fl(GL_POLYGON_OFFSET_FILL); + gpu_state_print_fl(GL_POLYGON_OFFSET_LINE); + gpu_state_print_fl(GL_POLYGON_OFFSET_POINT); + gpu_state_print_fl(GL_POLYGON_OFFSET_UNITS); + gpu_state_print_fl(GL_POLYGON_SMOOTH); + gpu_state_print_fl(GL_POLYGON_SMOOTH_HINT); + gpu_state_print_fl(GL_POLYGON_STIPPLE); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_ALPHA_BIAS); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_ALPHA_SCALE); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_BLUE_BIAS); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_BLUE_SCALE); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_COLOR_TABLE); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_GREEN_BIAS); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_GREEN_SCALE); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_RED_BIAS); + gpu_state_print_fl(GL_POST_COLOR_MATRIX_RED_SCALE); + gpu_state_print_fl(GL_POST_CONVOLUTION_ALPHA_BIAS); + gpu_state_print_fl(GL_POST_CONVOLUTION_ALPHA_SCALE); + gpu_state_print_fl(GL_POST_CONVOLUTION_BLUE_BIAS); + gpu_state_print_fl(GL_POST_CONVOLUTION_BLUE_SCALE); + gpu_state_print_fl(GL_POST_CONVOLUTION_COLOR_TABLE); + gpu_state_print_fl(GL_POST_CONVOLUTION_GREEN_BIAS); + gpu_state_print_fl(GL_POST_CONVOLUTION_GREEN_SCALE); + gpu_state_print_fl(GL_POST_CONVOLUTION_RED_BIAS); + gpu_state_print_fl(GL_POST_CONVOLUTION_RED_SCALE); + gpu_state_print_fl(GL_PROJECTION_MATRIX); + gpu_state_print_fl(GL_PROJECTION_STACK_DEPTH); + gpu_state_print_fl(GL_READ_BUFFER); + gpu_state_print_fl(GL_RED_BIAS); + gpu_state_print_fl(GL_RED_BITS); + gpu_state_print_fl(GL_RED_SCALE); + gpu_state_print_fl(GL_RENDER_MODE); + gpu_state_print_fl(GL_RESCALE_NORMAL); + gpu_state_print_fl(GL_RGBA_MODE); + gpu_state_print_fl(GL_SAMPLES); + gpu_state_print_fl(GL_SAMPLE_BUFFERS); + gpu_state_print_fl(GL_SAMPLE_COVERAGE_INVERT); + gpu_state_print_fl(GL_SAMPLE_COVERAGE_VALUE); + gpu_state_print_fl(GL_SCISSOR_BOX); + gpu_state_print_fl(GL_SCISSOR_TEST); + gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY); + gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_SIZE); + gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_STRIDE); + gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_TYPE); + gpu_state_print_fl(GL_SELECTION_BUFFER_SIZE); + gpu_state_print_fl(GL_SEPARABLE_2D); + gpu_state_print_fl(GL_SHADE_MODEL); + gpu_state_print_fl(GL_SMOOTH_LINE_WIDTH_GRANULARITY); + gpu_state_print_fl(GL_SMOOTH_LINE_WIDTH_RANGE); + gpu_state_print_fl(GL_SMOOTH_POINT_SIZE_GRANULARITY); + gpu_state_print_fl(GL_SMOOTH_POINT_SIZE_RANGE); + gpu_state_print_fl(GL_STENCIL_BACK_FAIL); + gpu_state_print_fl(GL_STENCIL_BACK_FUNC); + gpu_state_print_fl(GL_STENCIL_BACK_PASS_DEPTH_FAIL); + gpu_state_print_fl(GL_STENCIL_BACK_PASS_DEPTH_PASS); + gpu_state_print_fl(GL_STENCIL_BACK_REF); + gpu_state_print_fl(GL_STENCIL_BACK_VALUE_MASK); + gpu_state_print_fl(GL_STENCIL_BACK_WRITEMASK); + gpu_state_print_fl(GL_STENCIL_BITS); + gpu_state_print_fl(GL_STENCIL_CLEAR_VALUE); + gpu_state_print_fl(GL_STENCIL_FAIL); + gpu_state_print_fl(GL_STENCIL_FUNC); + gpu_state_print_fl(GL_STENCIL_PASS_DEPTH_FAIL); + gpu_state_print_fl(GL_STENCIL_PASS_DEPTH_PASS); + gpu_state_print_fl(GL_STENCIL_REF); + gpu_state_print_fl(GL_STENCIL_TEST); + gpu_state_print_fl(GL_STENCIL_VALUE_MASK); + gpu_state_print_fl(GL_STENCIL_WRITEMASK); + gpu_state_print_fl(GL_STEREO); + gpu_state_print_fl(GL_SUBPIXEL_BITS); + gpu_state_print_fl(GL_TEXTURE_1D); + gpu_state_print_fl(GL_TEXTURE_2D); + gpu_state_print_fl(GL_TEXTURE_3D); + gpu_state_print_fl(GL_TEXTURE_BINDING_1D); + gpu_state_print_fl(GL_TEXTURE_BINDING_2D); + gpu_state_print_fl(GL_TEXTURE_BINDING_3D); + gpu_state_print_fl(GL_TEXTURE_BINDING_CUBE_MAP); + gpu_state_print_fl(GL_TEXTURE_COMPRESSION_HINT); + gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY); + gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_SIZE); + gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_STRIDE); + gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_TYPE); + gpu_state_print_fl(GL_TEXTURE_CUBE_MAP); + gpu_state_print_fl(GL_TEXTURE_CUBE_MAP_ARB); + gpu_state_print_fl(GL_TEXTURE_GEN_Q); + gpu_state_print_fl(GL_TEXTURE_GEN_R); + gpu_state_print_fl(GL_TEXTURE_GEN_S); + gpu_state_print_fl(GL_TEXTURE_GEN_T); + gpu_state_print_fl(GL_TEXTURE_MATRIX); + gpu_state_print_fl(GL_TEXTURE_STACK_DEPTH); + gpu_state_print_fl(GL_TRANSPOSE_COLOR_MATRIX); + gpu_state_print_fl(GL_TRANSPOSE_MODELVIEW_MATRIX); + gpu_state_print_fl(GL_TRANSPOSE_PROJECTION_MATRIX); + gpu_state_print_fl(GL_TRANSPOSE_TEXTURE_MATRIX); + gpu_state_print_fl(GL_UNPACK_ALIGNMENT); + gpu_state_print_fl(GL_UNPACK_IMAGE_HEIGHT); + gpu_state_print_fl(GL_UNPACK_LSB_FIRST); + gpu_state_print_fl(GL_UNPACK_ROW_LENGTH); + gpu_state_print_fl(GL_UNPACK_SKIP_IMAGES); + gpu_state_print_fl(GL_UNPACK_SKIP_PIXELS); + gpu_state_print_fl(GL_UNPACK_SKIP_ROWS); + gpu_state_print_fl(GL_UNPACK_SWAP_BYTES); + gpu_state_print_fl(GL_VERTEX_ARRAY); + gpu_state_print_fl(GL_VERTEX_ARRAY_BUFFER_BINDING); + gpu_state_print_fl(GL_VERTEX_ARRAY_SIZE); + gpu_state_print_fl(GL_VERTEX_ARRAY_STRIDE); + gpu_state_print_fl(GL_VERTEX_ARRAY_TYPE); + gpu_state_print_fl(GL_VERTEX_PROGRAM_POINT_SIZE); + gpu_state_print_fl(GL_VERTEX_PROGRAM_TWO_SIDE); + gpu_state_print_fl(GL_VIEWPORT); + gpu_state_print_fl(GL_ZOOM_X); + gpu_state_print_fl(GL_ZOOM_Y); +} + +#undef gpu_state_print_fl + +#endif diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 7295f0259c5..729146e065b 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -36,9 +36,28 @@ * and abstract them away from the rest a bit. */ -#include <string.h> +/* my interface */ +#include "GPU_draw.h" + +/* internal */ +#include "intern/gpu_profile.h" +#include "intern/gpu_extensions_intern.h" +//#include "intern/gpu_raster_intern.h" + +/* my library */ +//#include "GPU_colors.h" +//#include "GPU_common.h" +#include "GPU_buffers.h" +#include "GPU_extensions.h" +//#include "GPU_lighting.h" +#include "GPU_material.h" +//#include "GPU_basic.h" +//#include "GPU_immediate.h" +//#include "GPU_matrix.h" +//#include "GPU_state_latch.h" +//#include "GPU_blender_aspect.h" -#include "GL/glew.h" +/* external */ #include "BLI_blenlib.h" #include "BLI_linklist.h" @@ -71,15 +90,15 @@ #include "BKE_scene.h" #include "BKE_DerivedMesh.h" -#include "GPU_buffers.h" -#include "GPU_draw.h" -#include "GPU_extensions.h" -#include "GPU_material.h" - #include "PIL_time.h" #include "smoke_API.h" +/* standard */ + +#include <string.h> + + extern Material defmaterial; /* from material.c */ /* Text Rendering */ @@ -261,25 +280,6 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap) } } -static void gpu_generate_mipmap(GLenum target) -{ - const bool is_ati = GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY); - int target_enabled = 0; - - /* work around bug in ATI driver, need to have GL_TEXTURE_2D enabled - * http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation */ - if (is_ati) { - target_enabled = glIsEnabled(target); - if (!target_enabled) - glEnable(target); - } - - glGenerateMipmapEXT(target); - - if (is_ati && !target_enabled) - glDisable(target); -} - void GPU_set_mipmap(int mipmap) { if (GTS.domipmap != (mipmap != 0)) { @@ -370,6 +370,14 @@ static void gpu_make_repbind(Image *ima) BKE_image_release_ibuf(ima, ibuf, NULL); } +static void blend_func_state_init(void) +{ + if (GLEW_VERSION_1_4) + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + else + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + void GPU_clear_tpage(bool force) { if (GTS.lasttface==NULL && !force) @@ -393,6 +401,8 @@ void GPU_clear_tpage(bool force) glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_ALPHA_TEST); + + blend_func_state_init(); } static void gpu_set_alpha_blend(GPUBlendMode alphablend) @@ -400,7 +410,7 @@ static void gpu_set_alpha_blend(GPUBlendMode alphablend) if (alphablend == GPU_BLEND_SOLID) { glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + blend_func_state_init(); } else if (alphablend==GPU_BLEND_ADD) { glEnable(GL_BLEND); @@ -738,7 +748,7 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix); - gpu_generate_mipmap(GL_TEXTURE_2D); + gpu_glGenerateMipmap(GL_TEXTURE_2D); } else { if (use_high_bit_depth) @@ -1010,7 +1020,7 @@ static bool GPU_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x, } if (GPU_get_mipmap()) { - gpu_generate_mipmap(GL_TEXTURE_2D); + gpu_glGenerateMipmap(GL_TEXTURE_2D); } else { ima->tpageflag &= ~IMA_MIPMAP_COMPLETE; @@ -1060,7 +1070,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h) /* we have already accounted for the case where GTS.gpu_mipmap is false * so we will be using GPU mipmap generation here */ if (GPU_get_mipmap()) { - gpu_generate_mipmap(GL_TEXTURE_2D); + gpu_glGenerateMipmap(GL_TEXTURE_2D); } else { ima->tpageflag &= ~IMA_MIPMAP_COMPLETE; @@ -1094,7 +1104,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h) /* see comment above as to why we are using gpu mipmap generation here */ if (GPU_get_mipmap()) { - gpu_generate_mipmap(GL_TEXTURE_2D); + gpu_glGenerateMipmap(GL_TEXTURE_2D); } else { ima->tpageflag &= ~IMA_MIPMAP_COMPLETE; @@ -1888,14 +1898,16 @@ void GPU_state_init(void) int a, x, y; GLubyte pat[32*32]; const GLubyte *patc= pat; - + + blend_func_state_init(); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 35); GPU_default_lights(); - + glDepthFunc(GL_LEQUAL); /* scaling matrices */ glEnable(GL_NORMALIZE); @@ -1939,7 +1951,7 @@ void GPU_state_init(void) else pat[a++]= 0x22; } } - + glPolygonStipple(patc); glMatrixMode(GL_TEXTURE); @@ -1950,395 +1962,26 @@ void GPU_state_init(void) glCullFace(GL_BACK); glDisable(GL_CULL_FACE); - /* calling this makes drawing very slow when AA is not set up in ghost - * on Linux/NVIDIA. */ - // glDisable(GL_MULTISAMPLE); -} + /* MULTISAMPLE is enabled by GL by default, but Blender needs to disable it by default + it will be enabled only by drawing code that needs it + apparently however, doing that makes drawing very slow when AA is not set up in GHOST on Linux/NVIDIA + so, let's check for that and leave it enabled in that case */ + if (GLEW_VERSION_1_3 || GLEW_ARB_multisample) { + bool disable_ok = true; -#ifdef DEBUG -/* debugging aid */ -static void gpu_state_print_fl_ex(const char *name, GLenum type) -{ - const unsigned char err_mark[4] = {0xff, 0xff, 0xff, 0xff}; - - float value[32]; - int a; + if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_UNIX, GPU_DRIVER_ANY)) { + int samples = 0; + glGetIntegerv(GL_SAMPLES, &samples); - memset(value, 0xff, sizeof(value)); - glGetFloatv(type, value); - - printf("%s: ", name); - for (a = 0; a < 32; a++) { - if (memcmp(&value[a], err_mark, sizeof(value[a])) == 0) { - break; + if (samples == 0) + disable_ok = false; // AA not set up, so it isn't OK to disable } - printf("%.2f ", value[a]); - } - printf("\n"); -} -#define gpu_state_print_fl(val) gpu_state_print_fl_ex(#val, val) + if (disable_ok) + glDisable(GL_MULTISAMPLE); + } -void GPU_state_print(void) -{ - gpu_state_print_fl(GL_ACCUM_ALPHA_BITS); - gpu_state_print_fl(GL_ACCUM_BLUE_BITS); - gpu_state_print_fl(GL_ACCUM_CLEAR_VALUE); - gpu_state_print_fl(GL_ACCUM_GREEN_BITS); - gpu_state_print_fl(GL_ACCUM_RED_BITS); - gpu_state_print_fl(GL_ACTIVE_TEXTURE); - gpu_state_print_fl(GL_ALIASED_LINE_WIDTH_RANGE); - gpu_state_print_fl(GL_ALIASED_POINT_SIZE_RANGE); - gpu_state_print_fl(GL_ALPHA_BIAS); - gpu_state_print_fl(GL_ALPHA_BITS); - gpu_state_print_fl(GL_ALPHA_SCALE); - gpu_state_print_fl(GL_ALPHA_TEST); - gpu_state_print_fl(GL_ALPHA_TEST_FUNC); - gpu_state_print_fl(GL_ALPHA_TEST_REF); - gpu_state_print_fl(GL_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_ATTRIB_STACK_DEPTH); - gpu_state_print_fl(GL_AUTO_NORMAL); - gpu_state_print_fl(GL_AUX_BUFFERS); - gpu_state_print_fl(GL_BLEND); - gpu_state_print_fl(GL_BLEND_COLOR); - gpu_state_print_fl(GL_BLEND_DST_ALPHA); - gpu_state_print_fl(GL_BLEND_DST_RGB); - gpu_state_print_fl(GL_BLEND_EQUATION_ALPHA); - gpu_state_print_fl(GL_BLEND_EQUATION_RGB); - gpu_state_print_fl(GL_BLEND_SRC_ALPHA); - gpu_state_print_fl(GL_BLEND_SRC_RGB); - gpu_state_print_fl(GL_BLUE_BIAS); - gpu_state_print_fl(GL_BLUE_BITS); - gpu_state_print_fl(GL_BLUE_SCALE); - gpu_state_print_fl(GL_CLIENT_ACTIVE_TEXTURE); - gpu_state_print_fl(GL_CLIENT_ATTRIB_STACK_DEPTH); - gpu_state_print_fl(GL_CLIP_PLANE0); - gpu_state_print_fl(GL_COLOR_ARRAY); - gpu_state_print_fl(GL_COLOR_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_COLOR_ARRAY_SIZE); - gpu_state_print_fl(GL_COLOR_ARRAY_STRIDE); - gpu_state_print_fl(GL_COLOR_ARRAY_TYPE); - gpu_state_print_fl(GL_COLOR_CLEAR_VALUE); - gpu_state_print_fl(GL_COLOR_LOGIC_OP); - gpu_state_print_fl(GL_COLOR_MATERIAL); - gpu_state_print_fl(GL_COLOR_MATERIAL_FACE); - gpu_state_print_fl(GL_COLOR_MATERIAL_PARAMETER); - gpu_state_print_fl(GL_COLOR_MATRIX); - gpu_state_print_fl(GL_COLOR_MATRIX_STACK_DEPTH); - gpu_state_print_fl(GL_COLOR_SUM); - gpu_state_print_fl(GL_COLOR_TABLE); - gpu_state_print_fl(GL_COLOR_WRITEMASK); - gpu_state_print_fl(GL_COMPRESSED_TEXTURE_FORMATS); - gpu_state_print_fl(GL_CONVOLUTION_1D); - gpu_state_print_fl(GL_CONVOLUTION_2D); - gpu_state_print_fl(GL_CULL_FACE); - gpu_state_print_fl(GL_CULL_FACE_MODE); - gpu_state_print_fl(GL_CURRENT_COLOR); - gpu_state_print_fl(GL_CURRENT_FOG_COORD); - gpu_state_print_fl(GL_CURRENT_INDEX); - gpu_state_print_fl(GL_CURRENT_NORMAL); - gpu_state_print_fl(GL_CURRENT_PROGRAM); - gpu_state_print_fl(GL_CURRENT_RASTER_COLOR); - gpu_state_print_fl(GL_CURRENT_RASTER_DISTANCE); - gpu_state_print_fl(GL_CURRENT_RASTER_INDEX); - gpu_state_print_fl(GL_CURRENT_RASTER_POSITION); - gpu_state_print_fl(GL_CURRENT_RASTER_POSITION_VALID); - gpu_state_print_fl(GL_CURRENT_RASTER_SECONDARY_COLOR); - gpu_state_print_fl(GL_CURRENT_RASTER_TEXTURE_COORDS); - gpu_state_print_fl(GL_CURRENT_SECONDARY_COLOR); - gpu_state_print_fl(GL_CURRENT_TEXTURE_COORDS); - gpu_state_print_fl(GL_DEPTH_BIAS); - gpu_state_print_fl(GL_DEPTH_BITS); - gpu_state_print_fl(GL_DEPTH_CLEAR_VALUE); - gpu_state_print_fl(GL_DEPTH_FUNC); - gpu_state_print_fl(GL_DEPTH_RANGE); - gpu_state_print_fl(GL_DEPTH_SCALE); - gpu_state_print_fl(GL_DEPTH_TEST); - gpu_state_print_fl(GL_DEPTH_WRITEMASK); - gpu_state_print_fl(GL_DITHER); - gpu_state_print_fl(GL_DOUBLEBUFFER); - gpu_state_print_fl(GL_DRAW_BUFFER); - gpu_state_print_fl(GL_DRAW_BUFFER0); - gpu_state_print_fl(GL_EDGE_FLAG); - gpu_state_print_fl(GL_EDGE_FLAG_ARRAY); - gpu_state_print_fl(GL_EDGE_FLAG_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_EDGE_FLAG_ARRAY_STRIDE); - gpu_state_print_fl(GL_ELEMENT_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_FEEDBACK_BUFFER_SIZE); - gpu_state_print_fl(GL_FEEDBACK_BUFFER_TYPE); - gpu_state_print_fl(GL_FOG); - gpu_state_print_fl(GL_FOG_COLOR); - gpu_state_print_fl(GL_FOG_COORD_ARRAY); - gpu_state_print_fl(GL_FOG_COORD_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_FOG_COORD_ARRAY_STRIDE); - gpu_state_print_fl(GL_FOG_COORD_ARRAY_TYPE); - gpu_state_print_fl(GL_FOG_COORD_SRC); - gpu_state_print_fl(GL_FOG_DENSITY); - gpu_state_print_fl(GL_FOG_END); - gpu_state_print_fl(GL_FOG_HINT); - gpu_state_print_fl(GL_FOG_INDEX); - gpu_state_print_fl(GL_FOG_MODE); - gpu_state_print_fl(GL_FOG_START); - gpu_state_print_fl(GL_FRAGMENT_PROGRAM_ARB); - gpu_state_print_fl(GL_FRAGMENT_SHADER_DERIVATIVE_HINT); - gpu_state_print_fl(GL_FRONT_FACE); - gpu_state_print_fl(GL_GENERATE_MIPMAP_HINT); - gpu_state_print_fl(GL_GREEN_BIAS); - gpu_state_print_fl(GL_GREEN_BITS); - gpu_state_print_fl(GL_GREEN_SCALE); - gpu_state_print_fl(GL_HISTOGRAM); - gpu_state_print_fl(GL_INDEX_ARRAY); - gpu_state_print_fl(GL_INDEX_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_INDEX_ARRAY_STRIDE); - gpu_state_print_fl(GL_INDEX_ARRAY_TYPE); - gpu_state_print_fl(GL_INDEX_BITS); - gpu_state_print_fl(GL_INDEX_CLEAR_VALUE); - gpu_state_print_fl(GL_INDEX_LOGIC_OP); - gpu_state_print_fl(GL_INDEX_MODE); - gpu_state_print_fl(GL_INDEX_OFFSET); - gpu_state_print_fl(GL_INDEX_SHIFT); - gpu_state_print_fl(GL_INDEX_WRITEMASK); - gpu_state_print_fl(GL_LIGHT0); - gpu_state_print_fl(GL_LIGHT1); - gpu_state_print_fl(GL_LIGHT2); - gpu_state_print_fl(GL_LIGHT3); - gpu_state_print_fl(GL_LIGHT4); - gpu_state_print_fl(GL_LIGHT5); - gpu_state_print_fl(GL_LIGHT6); - gpu_state_print_fl(GL_LIGHT7); - gpu_state_print_fl(GL_LIGHTING); - gpu_state_print_fl(GL_LIGHT_MODEL_AMBIENT); - gpu_state_print_fl(GL_LIGHT_MODEL_COLOR_CONTROL); - gpu_state_print_fl(GL_LIGHT_MODEL_LOCAL_VIEWER); - gpu_state_print_fl(GL_LIGHT_MODEL_TWO_SIDE); - gpu_state_print_fl(GL_LINE_SMOOTH); - gpu_state_print_fl(GL_LINE_SMOOTH_HINT); - gpu_state_print_fl(GL_LINE_STIPPLE); - gpu_state_print_fl(GL_LINE_STIPPLE_PATTERN); - gpu_state_print_fl(GL_LINE_STIPPLE_REPEAT); - gpu_state_print_fl(GL_LINE_WIDTH); - gpu_state_print_fl(GL_LINE_WIDTH_GRANULARITY); - gpu_state_print_fl(GL_LINE_WIDTH_RANGE); - gpu_state_print_fl(GL_LIST_BASE); - gpu_state_print_fl(GL_LIST_INDEX); - gpu_state_print_fl(GL_LIST_MODE); - gpu_state_print_fl(GL_LOGIC_OP); - gpu_state_print_fl(GL_LOGIC_OP_MODE); - gpu_state_print_fl(GL_MAP1_COLOR_4); - gpu_state_print_fl(GL_MAP1_GRID_DOMAIN); - gpu_state_print_fl(GL_MAP1_GRID_SEGMENTS); - gpu_state_print_fl(GL_MAP1_INDEX); - gpu_state_print_fl(GL_MAP1_NORMAL); - gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_1); - gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_2); - gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_3); - gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_4); - gpu_state_print_fl(GL_MAP1_VERTEX_3); - gpu_state_print_fl(GL_MAP1_VERTEX_4); - gpu_state_print_fl(GL_MAP2_COLOR_4); - gpu_state_print_fl(GL_MAP2_GRID_DOMAIN); - gpu_state_print_fl(GL_MAP2_GRID_SEGMENTS); - gpu_state_print_fl(GL_MAP2_INDEX); - gpu_state_print_fl(GL_MAP2_NORMAL); - gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_1); - gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_2); - gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_3); - gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_4); - gpu_state_print_fl(GL_MAP2_VERTEX_3); - gpu_state_print_fl(GL_MAP2_VERTEX_4); - gpu_state_print_fl(GL_MAP_COLOR); - gpu_state_print_fl(GL_MAP_STENCIL); - gpu_state_print_fl(GL_MATRIX_MODE); - gpu_state_print_fl(GL_MAX_3D_TEXTURE_SIZE); - gpu_state_print_fl(GL_MAX_ATTRIB_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_CLIENT_ATTRIB_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_CLIP_PLANES); - gpu_state_print_fl(GL_MAX_COLOR_MATRIX_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS); - gpu_state_print_fl(GL_MAX_CUBE_MAP_TEXTURE_SIZE); - gpu_state_print_fl(GL_MAX_DRAW_BUFFERS); - gpu_state_print_fl(GL_MAX_ELEMENTS_INDICES); - gpu_state_print_fl(GL_MAX_ELEMENTS_VERTICES); - gpu_state_print_fl(GL_MAX_EVAL_ORDER); - gpu_state_print_fl(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS); - gpu_state_print_fl(GL_MAX_LIGHTS); - gpu_state_print_fl(GL_MAX_LIST_NESTING); - gpu_state_print_fl(GL_MAX_MODELVIEW_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_NAME_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_PIXEL_MAP_TABLE); - gpu_state_print_fl(GL_MAX_PROJECTION_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_TEXTURE_COORDS); - gpu_state_print_fl(GL_MAX_TEXTURE_IMAGE_UNITS); - gpu_state_print_fl(GL_MAX_TEXTURE_LOD_BIAS); - gpu_state_print_fl(GL_MAX_TEXTURE_SIZE); - gpu_state_print_fl(GL_MAX_TEXTURE_STACK_DEPTH); - gpu_state_print_fl(GL_MAX_TEXTURE_UNITS); - gpu_state_print_fl(GL_MAX_VARYING_FLOATS); - gpu_state_print_fl(GL_MAX_VERTEX_ATTRIBS); - gpu_state_print_fl(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS); - gpu_state_print_fl(GL_MAX_VERTEX_UNIFORM_COMPONENTS); - gpu_state_print_fl(GL_MAX_VIEWPORT_DIMS); - gpu_state_print_fl(GL_MINMAX); - gpu_state_print_fl(GL_MODELVIEW_MATRIX); - gpu_state_print_fl(GL_MODELVIEW_STACK_DEPTH); - gpu_state_print_fl(GL_MULTISAMPLE); - gpu_state_print_fl(GL_MULTISAMPLE_ARB); - gpu_state_print_fl(GL_NAME_STACK_DEPTH); - gpu_state_print_fl(GL_NORMALIZE); - gpu_state_print_fl(GL_NORMAL_ARRAY); - gpu_state_print_fl(GL_NORMAL_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_NORMAL_ARRAY_STRIDE); - gpu_state_print_fl(GL_NORMAL_ARRAY_TYPE); - gpu_state_print_fl(GL_NUM_COMPRESSED_TEXTURE_FORMATS); - gpu_state_print_fl(GL_PACK_ALIGNMENT); - gpu_state_print_fl(GL_PACK_IMAGE_HEIGHT); - gpu_state_print_fl(GL_PACK_LSB_FIRST); - gpu_state_print_fl(GL_PACK_ROW_LENGTH); - gpu_state_print_fl(GL_PACK_SKIP_IMAGES); - gpu_state_print_fl(GL_PACK_SKIP_PIXELS); - gpu_state_print_fl(GL_PACK_SKIP_ROWS); - gpu_state_print_fl(GL_PACK_SWAP_BYTES); - gpu_state_print_fl(GL_PERSPECTIVE_CORRECTION_HINT); - gpu_state_print_fl(GL_PIXEL_MAP_A_TO_A_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_B_TO_B_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_G_TO_G_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_I_TO_A_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_I_TO_B_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_I_TO_G_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_I_TO_I_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_I_TO_R_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_R_TO_R_SIZE); - gpu_state_print_fl(GL_PIXEL_MAP_S_TO_S_SIZE); - gpu_state_print_fl(GL_PIXEL_PACK_BUFFER_BINDING); - gpu_state_print_fl(GL_PIXEL_UNPACK_BUFFER_BINDING); - gpu_state_print_fl(GL_POINT_DISTANCE_ATTENUATION); - gpu_state_print_fl(GL_POINT_FADE_THRESHOLD_SIZE); - gpu_state_print_fl(GL_POINT_SIZE); - gpu_state_print_fl(GL_POINT_SIZE_GRANULARITY); - gpu_state_print_fl(GL_POINT_SIZE_MAX); - gpu_state_print_fl(GL_POINT_SIZE_MIN); - gpu_state_print_fl(GL_POINT_SIZE_RANGE); - gpu_state_print_fl(GL_POINT_SMOOTH); - gpu_state_print_fl(GL_POINT_SMOOTH_HINT); - gpu_state_print_fl(GL_POINT_SPRITE); - gpu_state_print_fl(GL_POLYGON_MODE); - gpu_state_print_fl(GL_POLYGON_OFFSET_FACTOR); - gpu_state_print_fl(GL_POLYGON_OFFSET_FILL); - gpu_state_print_fl(GL_POLYGON_OFFSET_LINE); - gpu_state_print_fl(GL_POLYGON_OFFSET_POINT); - gpu_state_print_fl(GL_POLYGON_OFFSET_UNITS); - gpu_state_print_fl(GL_POLYGON_SMOOTH); - gpu_state_print_fl(GL_POLYGON_SMOOTH_HINT); - gpu_state_print_fl(GL_POLYGON_STIPPLE); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_ALPHA_BIAS); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_ALPHA_SCALE); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_BLUE_BIAS); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_BLUE_SCALE); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_COLOR_TABLE); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_GREEN_BIAS); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_GREEN_SCALE); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_RED_BIAS); - gpu_state_print_fl(GL_POST_COLOR_MATRIX_RED_SCALE); - gpu_state_print_fl(GL_POST_CONVOLUTION_ALPHA_BIAS); - gpu_state_print_fl(GL_POST_CONVOLUTION_ALPHA_SCALE); - gpu_state_print_fl(GL_POST_CONVOLUTION_BLUE_BIAS); - gpu_state_print_fl(GL_POST_CONVOLUTION_BLUE_SCALE); - gpu_state_print_fl(GL_POST_CONVOLUTION_COLOR_TABLE); - gpu_state_print_fl(GL_POST_CONVOLUTION_GREEN_BIAS); - gpu_state_print_fl(GL_POST_CONVOLUTION_GREEN_SCALE); - gpu_state_print_fl(GL_POST_CONVOLUTION_RED_BIAS); - gpu_state_print_fl(GL_POST_CONVOLUTION_RED_SCALE); - gpu_state_print_fl(GL_PROJECTION_MATRIX); - gpu_state_print_fl(GL_PROJECTION_STACK_DEPTH); - gpu_state_print_fl(GL_READ_BUFFER); - gpu_state_print_fl(GL_RED_BIAS); - gpu_state_print_fl(GL_RED_BITS); - gpu_state_print_fl(GL_RED_SCALE); - gpu_state_print_fl(GL_RENDER_MODE); - gpu_state_print_fl(GL_RESCALE_NORMAL); - gpu_state_print_fl(GL_RGBA_MODE); - gpu_state_print_fl(GL_SAMPLES); - gpu_state_print_fl(GL_SAMPLE_BUFFERS); - gpu_state_print_fl(GL_SAMPLE_COVERAGE_INVERT); - gpu_state_print_fl(GL_SAMPLE_COVERAGE_VALUE); - gpu_state_print_fl(GL_SCISSOR_BOX); - gpu_state_print_fl(GL_SCISSOR_TEST); - gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY); - gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_SIZE); - gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_STRIDE); - gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_TYPE); - gpu_state_print_fl(GL_SELECTION_BUFFER_SIZE); - gpu_state_print_fl(GL_SEPARABLE_2D); - gpu_state_print_fl(GL_SHADE_MODEL); - gpu_state_print_fl(GL_SMOOTH_LINE_WIDTH_GRANULARITY); - gpu_state_print_fl(GL_SMOOTH_LINE_WIDTH_RANGE); - gpu_state_print_fl(GL_SMOOTH_POINT_SIZE_GRANULARITY); - gpu_state_print_fl(GL_SMOOTH_POINT_SIZE_RANGE); - gpu_state_print_fl(GL_STENCIL_BACK_FAIL); - gpu_state_print_fl(GL_STENCIL_BACK_FUNC); - gpu_state_print_fl(GL_STENCIL_BACK_PASS_DEPTH_FAIL); - gpu_state_print_fl(GL_STENCIL_BACK_PASS_DEPTH_PASS); - gpu_state_print_fl(GL_STENCIL_BACK_REF); - gpu_state_print_fl(GL_STENCIL_BACK_VALUE_MASK); - gpu_state_print_fl(GL_STENCIL_BACK_WRITEMASK); - gpu_state_print_fl(GL_STENCIL_BITS); - gpu_state_print_fl(GL_STENCIL_CLEAR_VALUE); - gpu_state_print_fl(GL_STENCIL_FAIL); - gpu_state_print_fl(GL_STENCIL_FUNC); - gpu_state_print_fl(GL_STENCIL_PASS_DEPTH_FAIL); - gpu_state_print_fl(GL_STENCIL_PASS_DEPTH_PASS); - gpu_state_print_fl(GL_STENCIL_REF); - gpu_state_print_fl(GL_STENCIL_TEST); - gpu_state_print_fl(GL_STENCIL_VALUE_MASK); - gpu_state_print_fl(GL_STENCIL_WRITEMASK); - gpu_state_print_fl(GL_STEREO); - gpu_state_print_fl(GL_SUBPIXEL_BITS); - gpu_state_print_fl(GL_TEXTURE_1D); - gpu_state_print_fl(GL_TEXTURE_2D); - gpu_state_print_fl(GL_TEXTURE_3D); - gpu_state_print_fl(GL_TEXTURE_BINDING_1D); - gpu_state_print_fl(GL_TEXTURE_BINDING_2D); - gpu_state_print_fl(GL_TEXTURE_BINDING_3D); - gpu_state_print_fl(GL_TEXTURE_BINDING_CUBE_MAP); - gpu_state_print_fl(GL_TEXTURE_COMPRESSION_HINT); - gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY); - gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_SIZE); - gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_STRIDE); - gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_TYPE); - gpu_state_print_fl(GL_TEXTURE_CUBE_MAP); - gpu_state_print_fl(GL_TEXTURE_CUBE_MAP_ARB); - gpu_state_print_fl(GL_TEXTURE_GEN_Q); - gpu_state_print_fl(GL_TEXTURE_GEN_R); - gpu_state_print_fl(GL_TEXTURE_GEN_S); - gpu_state_print_fl(GL_TEXTURE_GEN_T); - gpu_state_print_fl(GL_TEXTURE_MATRIX); - gpu_state_print_fl(GL_TEXTURE_STACK_DEPTH); - gpu_state_print_fl(GL_TRANSPOSE_COLOR_MATRIX); - gpu_state_print_fl(GL_TRANSPOSE_MODELVIEW_MATRIX); - gpu_state_print_fl(GL_TRANSPOSE_PROJECTION_MATRIX); - gpu_state_print_fl(GL_TRANSPOSE_TEXTURE_MATRIX); - gpu_state_print_fl(GL_UNPACK_ALIGNMENT); - gpu_state_print_fl(GL_UNPACK_IMAGE_HEIGHT); - gpu_state_print_fl(GL_UNPACK_LSB_FIRST); - gpu_state_print_fl(GL_UNPACK_ROW_LENGTH); - gpu_state_print_fl(GL_UNPACK_SKIP_IMAGES); - gpu_state_print_fl(GL_UNPACK_SKIP_PIXELS); - gpu_state_print_fl(GL_UNPACK_SKIP_ROWS); - gpu_state_print_fl(GL_UNPACK_SWAP_BYTES); - gpu_state_print_fl(GL_VERTEX_ARRAY); - gpu_state_print_fl(GL_VERTEX_ARRAY_BUFFER_BINDING); - gpu_state_print_fl(GL_VERTEX_ARRAY_SIZE); - gpu_state_print_fl(GL_VERTEX_ARRAY_STRIDE); - gpu_state_print_fl(GL_VERTEX_ARRAY_TYPE); - gpu_state_print_fl(GL_VERTEX_PROGRAM_POINT_SIZE); - gpu_state_print_fl(GL_VERTEX_PROGRAM_TWO_SIDE); - gpu_state_print_fl(GL_VIEWPORT); - gpu_state_print_fl(GL_ZOOM_X); - gpu_state_print_fl(GL_ZOOM_Y); + /* make sure double side isn't used by default and only getting enabled in places where it's + * really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */ + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); } - -#undef gpu_state_print_fl - -#endif diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 17c495c82d6..310b46266d3 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -20,7 +20,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): Brecht Van Lommel. + * Contributor(s): Brecht Van Lommel, Jason Wilkins. * * ***** END GPL LICENSE BLOCK ***** */ @@ -32,31 +32,52 @@ * with checks for drivers and GPU support. */ +#define GPU_MANGLE_DEPRECATED 0 -#include "GL/glew.h" +/* my interface */ +#define GPU_FUNC_INTERN +#include "intern/gpu_extensions_intern.h" -#include "DNA_image_types.h" +/* internal */ +#include "intern/gpu_codegen.h" +#include "intern/gpu_profile.h" +#include "intern/gpu_common_intern.h" -#include "MEM_guardedalloc.h" +/* my library */ +//#include "GPU_basic.h" +#include "GPU_draw.h" +//#include "GPU_font.h" +//#include "GPU_pixels.h" +//#include "GPU_raster.h" +#include "GPU_safety.h" +//#include "GPU_matrix.h" +//#include "GPU_aspect.h" +//#include "GPU_blender_aspect.h" +//#include "GPU_immediate.h" +#include "GPU_utility.h" +//#include "GPU_state_latch.h" + +/* external */ #include "BLI_blenlib.h" #include "BLI_utildefines.h" #include "BLI_math_base.h" +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif + #include "BKE_global.h" -#include "GPU_draw.h" -#include "GPU_extensions.h" -#include "GPU_simple_shader.h" -#include "gpu_codegen.h" +#include "DNA_image_types.h" +#include "MEM_guardedalloc.h" + +/* standard*/ #include <stdlib.h> #include <stdio.h> #include <string.h> -#ifdef WIN32 -# include "BLI_winstuff.h" -#endif #define MAX_DEFINE_LENGTH 72 @@ -87,11 +108,12 @@ static struct GPUGlobal { GLint maxtexsize; GLint maxtextures; GLuint currentfb; - int glslsupport; - int extdisabled; - int colordepth; - int npotdisabled; /* ATI 3xx-5xx (and more) chipsets support NPoT partially (== not enough) */ - int dlistsdisabled; /* Legacy ATI driver does not support display lists well */ + GLboolean glslsupport; + GLboolean framebuffersupport; + GLboolean extdisabled; + GLint colordepth; + GLboolean npotdisabled; /* ATI 3xx-5xx (and more) chipsets support NPoT partially (== not enough) */ + GLboolean dlistsdisabled; /* Legacy ATI driver does not support display lists well */ GPUDeviceType device; GPUOSType os; GPUDriverType driver; @@ -99,7 +121,7 @@ static struct GPUGlobal { GPUTexture *invalid_tex_1D; /* texture used in place of invalid textures (not loaded correctly, missing) */ GPUTexture *invalid_tex_2D; GPUTexture *invalid_tex_3D; -} GG = {1, 0}; +} GG; /* GPU Types */ @@ -110,11 +132,9 @@ int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver) /* GPU Extensions */ -static int gpu_extensions_init = 0; - void GPU_extensions_disable(void) { - GG.extdisabled = 1; + GG.extdisabled = GL_TRUE; } int GPU_max_texture_size(void) @@ -122,36 +142,73 @@ int GPU_max_texture_size(void) return GG.maxtexsize; } -void GPU_extensions_init(void) + +/* +Computes the maximum number of textures 'n' that +can be referenced by ActiveTexture(TEXTURE0+n-1) + +This is for any use of ActiveTexture. + +Individual limits, such as for the multitexture extension, gl_TexCoord, +vertex shaders, fragment shader, etc. will each have different limits. +*/ +static GLint get_max_textures(void) { - GLint r, g, b; - const char *vendor, *renderer; + GLint maxTextureUnits; + GLint maxTextureCoords; + GLint maxCombinedTextureImageUnits; + + /* There has to be at least one texture so count that here */ + maxTextureUnits = 1; + +#if !defined(GLEW_ES_ONLY) + if (GPU_PROFILE_COMPAT && (GLEW_VERSION_1_3 || GLEW_ARB_multitexture)) { + /* Multitexture typically supports only 2 or 4 texture stages even on modern hardware. */ + glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextureUnits); + } +#endif - /* can't avoid calling this multiple times, see wm_window_add_ghostwindow */ - if (gpu_extensions_init) return; - gpu_extensions_init= 1; + /* Set to zero here in case they do not get set later */ + maxTextureCoords = 0; + maxCombinedTextureImageUnits = 0; - glewInit(); - GPU_codegen_init(); + if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0 || GLEW_ARB_fragment_program) { +#if !defined(GLEW_ES_ONLY) + if (GPU_PROFILE_COMPAT) { + /* size of gl_TexCoord array in GLSL */ + glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxTextureCoords); + } +#endif - /* glewIsSupported("GL_VERSION_2_0") */ + /* Number of textures accessible by vertex, fragment, and geometry shaders combined. */ + /* Individually the limits for each of those programmable units may be smaller. */ + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxCombinedTextureImageUnits); + } - if (GLEW_ARB_multitexture) - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures); + return MAX3(maxTextureUnits, maxTextureCoords, maxCombinedTextureImageUnits); +} - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GG.maxtexsize); +int GPU_max_textures(void) +{ + return GG.maxtextures; +} - GG.glslsupport = 1; - if (!GLEW_ARB_multitexture) GG.glslsupport = 0; - if (!GLEW_ARB_vertex_shader) GG.glslsupport = 0; - if (!GLEW_ARB_fragment_shader) GG.glslsupport = 0; +static void shim_init(void); - glGetIntegerv(GL_RED_BITS, &r); - glGetIntegerv(GL_GREEN_BITS, &g); - glGetIntegerv(GL_BLUE_BITS, &b); - GG.colordepth = r+g+b; /* assumes same depth for RGB */ +void gpu_extensions_init(void) +{ + GLint r, g, b; + const char *vendor, *renderer; + + GPU_CHECK_NO_ERROR(); + + shim_init(); + + GG.maxtextures = get_max_textures(); + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GG.maxtexsize); - vendor = (const char *)glGetString(GL_VENDOR); + vendor = (const char *)glGetString(GL_VENDOR); renderer = (const char *)glGetString(GL_RENDERER); if (strstr(vendor, "ATI")) { @@ -202,24 +259,20 @@ void GPU_extensions_init(void) /* This list is close enough to those using the legacy driver which * has a bug with display lists and glVertexAttrib */ - if (strstr(renderer, "R3") || strstr(renderer, "RV3") || - strstr(renderer, "R4") || strstr(renderer, "RV4") || - strstr(renderer, "RS4") || strstr(renderer, "RC4") || - strstr(renderer, "R5") || strstr(renderer, "RV5") || - strstr(renderer, "RS600") || strstr(renderer, "RS690") || - strstr(renderer, "RS740") || strstr(renderer, "X1") || - strstr(renderer, "X2") || strstr(renderer, "Radeon 9") || + if (strstr(renderer, "R3") || strstr(renderer, "RV3") || + strstr(renderer, "R4") || strstr(renderer, "RV4") || + strstr(renderer, "RS4") || strstr(renderer, "RC4") || + strstr(renderer, "R5") || strstr(renderer, "RV5") || + strstr(renderer, "RS600") || strstr(renderer, "RS690") || + strstr(renderer, "RS740") || strstr(renderer, "X1") || + strstr(renderer, "X2") || strstr(renderer, "Radeon 9") || strstr(renderer, "RADEON 9")) { - GG.npotdisabled = 1; - GG.dlistsdisabled = 1; + GG.npotdisabled = GL_TRUE; + GG.dlistsdisabled = GL_TRUE; } } - /* make sure double side isn't used by default and only getting enabled in places where it's - * really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */ - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - #ifdef _WIN32 GG.os = GPU_OS_WIN; #elif defined(__APPLE__) @@ -228,17 +281,39 @@ void GPU_extensions_init(void) GG.os = GPU_OS_UNIX; #endif + if (GPU_PROFILE_CORE) { +#if defined(WITH_GL_PROFILE_CORE) + if (!GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) { + glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &r); + glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &g); + glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &b); + } + else { + r=g=b=8;// XXX jwilkins: above code seems like it should work but doesn't due to driver bug(?) will probably need to forward this from ghost + } +#endif + } + else + { +#if defined(WITH_GL_PROFILE_COMPAT) || defined(WITH_GL_PROFILE_ES20) + glGetIntegerv(GL_RED_BITS, &r); + glGetIntegerv(GL_GREEN_BITS, &g); + glGetIntegerv(GL_BLUE_BITS, &b); +#endif + } + + GG.colordepth = r+g+b; /* assumes same depth for RGB */ GPU_invalid_tex_init(); - GPU_simple_shaders_init(); + + GPU_CHECK_NO_ERROR(); } -void GPU_extensions_exit(void) +void gpu_extensions_exit(void) { - gpu_extensions_init = 0; - GPU_codegen_exit(); - GPU_simple_shaders_exit(); + GPU_CHECK_NO_ERROR(); GPU_invalid_tex_free(); + GPU_CHECK_NO_ERROR(); } int GPU_glsl_support(void) @@ -248,10 +323,7 @@ int GPU_glsl_support(void) int GPU_non_power_of_two_support(void) { - if (GG.npotdisabled) - return 0; - - return GLEW_ARB_texture_non_power_of_two; + return GG.npotdisabled ? 0 : GLEW_ARB_texture_non_power_of_two; } int GPU_display_list_support(void) @@ -264,18 +336,18 @@ int GPU_color_depth(void) return GG.colordepth; } -int GPU_print_error(const char *str) +bool GPU_print_error(const char *str) { GLenum errCode; if (G.debug & G_DEBUG) { if ((errCode = glGetError()) != GL_NO_ERROR) { - fprintf(stderr, "%s opengl error: %s\n", str, gluErrorString(errCode)); - return 1; + fprintf(stderr, "%s: OpenGL Error: %s\n", str, gpuErrorString(errCode)); + return true; } } - return 0; + return false; } static void GPU_print_framebuffer_error(GLenum status, char err_out[256]) @@ -283,30 +355,30 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256]) const char *err= "unknown"; switch (status) { - case GL_FRAMEBUFFER_COMPLETE_EXT: + case GL_FRAMEBUFFER_COMPLETE: break; case GL_INVALID_OPERATION: err= "Invalid operation"; break; - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: err= "Incomplete attachment"; break; - case GL_FRAMEBUFFER_UNSUPPORTED_EXT: + case GL_FRAMEBUFFER_UNSUPPORTED: err= "Unsupported framebuffer format"; break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: err= "Missing attachment"; break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: err= "Attached images must have same dimensions"; break; - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS: err= "Attached images must have same format"; break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: err= "Missing draw buffer"; break; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: err= "Missing read buffer"; break; } @@ -324,15 +396,21 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256]) /* 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? */ + 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? + +#if !defined(GLEW_NO_ES) + // XXX jwilkins: for saving original data for shader export in ES + GLuint pixels_w, pixels_h; + GLvoid* pixels; +#endif }; static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels) @@ -343,7 +421,7 @@ static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels) len = 4*length; fp = fpixels; - p = pixels = MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels"); + p = pixels = (unsigned char*)MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels"); for (a=0; a<len; a++, p++, fp++) *p = FTOCHAR((*fp)); @@ -351,9 +429,9 @@ static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels) return pixels; } -static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h) +static void tex_sub_image_empty(GLenum target, GLenum format, int x, int y, int w, int h) { - void *pixels = MEM_callocN(sizeof(char)*4*w*h, "GPUTextureEmptyPixels"); + void *pixels = MEM_callocN(sizeof(char)*4*w*h, "tex_sub_image_empty"); if (target == GL_TEXTURE_1D) glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels); @@ -425,7 +503,7 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in pixels ? pixels : fpixels); if (tex->w > w) - GPU_glTexSubImageEmpty(tex->target, format, w, 0, + tex_sub_image_empty(tex->target, format, w, 0, tex->w-w, 1); } } @@ -438,9 +516,9 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in format, type, pixels ? pixels : fpixels); if (tex->w > w) - GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h); + tex_sub_image_empty(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); + tex_sub_image_empty(tex->target, format, 0, h, w, tex->h-h); } } @@ -590,7 +668,8 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, ima->gputexture= tex; if (!glIsTexture(tex->bindcode)) { - GPU_print_error("Blender Texture Not Loaded"); + if (G.debug & G_DEBUG) + fprintf(stderr, "Blender Texture Not Loaded"); } else { glBindTexture(GL_TEXTURE_2D, tex->bindcode); @@ -689,18 +768,23 @@ GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]) */ GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]) { - GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, err_out); + if (GLEW_ARB_texture_rg || (GLEW_EXT_texture_rg && GLEW_EXT_texture_storage)) { + GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, err_out); - if (tex) { - /* Now we tweak some of the settings */ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, size, size, 0, GL_RG, GL_FLOAT, NULL); + if (tex) { + /* Now we tweak some of the settings */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, size, size, 0, GL_RG, GL_FLOAT, NULL); - GPU_texture_unbind(tex); - } + GPU_texture_unbind(tex); + } - return tex; + return tex; + } + else { + return NULL; + } } void GPU_invalid_tex_init(void) @@ -825,7 +909,7 @@ int GPU_texture_opengl_height(GPUTexture *tex) return tex->h; } -int GPU_texture_opengl_bindcode(GPUTexture *tex) +int GPU_texture_opengl_bindcode(const GPUTexture *tex) { return tex->bindcode; } @@ -835,6 +919,31 @@ GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex) return tex->fb; } +unsigned char* GPU_texture_dup_pixels(const GPUTexture *tex, size_t* count) +{ + unsigned char* texpixels; + +#if !defined(GLEW_NO_ES) + *count = tex->pixels_w * tex->pixels_h; +#else + *count = tex->w * tex->h; +#endif + + texpixels = (unsigned char*)MEM_mallocN(4*(*count), "RGBApixels"); + +#if !defined(GLEW_NO_ES) + memcpy(texpixels, tex->pixels, 4*(*count)); +#else + { + glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(tex)); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, texpixels); + glBindTexture(GL_TEXTURE_2D, 0); /* restore default */ + } +#endif + + return texpixels; +} + /* GPUFrameBuffer */ struct GPUFrameBuffer { @@ -847,40 +956,48 @@ GPUFrameBuffer *GPU_framebuffer_create(void) { GPUFrameBuffer *fb; - if (!GLEW_EXT_framebuffer_object) + if (GG.extdisabled || !GG.framebuffersupport) return NULL; - - fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer"); - glGenFramebuffersEXT(1, &fb->object); + + fb = (GPUFrameBuffer*)MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer"); + gpu_glGenFramebuffers(1, &fb->object); if (!fb->object) { - fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n", - (int)glGetError()); + fprintf( + stderr, + "GPU_framebuffer_create: framebuffer gen failed. %s\n", + gpuErrorString(glGetError())); + GPU_framebuffer_free(fb); + return NULL; } - - return fb; + else { + return fb; + } } -int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]) +bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]) { GLenum status; GLenum attachment; GLenum error; + if (GG.extdisabled) + return false; + if (tex->depth) - attachment = GL_DEPTH_ATTACHMENT_EXT; + attachment = GL_DEPTH_ATTACHMENT; else - attachment = GL_COLOR_ATTACHMENT0_EXT; + attachment = GL_COLOR_ATTACHMENT0; - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object); + gpu_glBindFramebuffer(GL_FRAMEBUFFER, fb->object); GG.currentfb = fb->object; /* Clean glError buffer. */ while (glGetError() != GL_NO_ERROR) {} - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, + gpu_glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, tex->target, tex->bindcode, 0); error = glGetError(); @@ -888,24 +1005,26 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err if (error == GL_INVALID_OPERATION) { GPU_framebuffer_restore(); GPU_print_framebuffer_error(error, err_out); - return 0; + return false; } +#if !defined(GLEW_ES_ONLY) // XXX jwilkins: i think ES20 can only access COLOR_ATTACHMENT0 anyway if (tex->depth) { glDrawBuffer(GL_NONE); - glReadBuffer(GL_NONE); + glReadBuffer(GL_NONE); // XXX jwilkins: this is an invalid value! } else { - glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0); + glReadBuffer(GL_COLOR_ATTACHMENT0); } +#endif - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + status = gpu_glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + if (status != GL_FRAMEBUFFER_COMPLETE) { GPU_framebuffer_restore(); GPU_print_framebuffer_error(status, err_out); - return 0; + return false; } if (tex->depth) @@ -915,44 +1034,59 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err tex->fb= fb; - return 1; + return true; } void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex) { GLenum attachment; + if (GG.extdisabled) + return; + if (!tex->fb) return; if (GG.currentfb != tex->fb->object) { - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object); + gpu_glBindFramebuffer(GL_FRAMEBUFFER, tex->fb->object); GG.currentfb = tex->fb->object; } if (tex->depth) { fb->depthtex = NULL; - attachment = GL_DEPTH_ATTACHMENT_EXT; + attachment = GL_DEPTH_ATTACHMENT; } else { fb->colortex = NULL; - attachment = GL_COLOR_ATTACHMENT0_EXT; + attachment = GL_COLOR_ATTACHMENT0; } - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, + gpu_glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, tex->target, 0, 0); tex->fb = NULL; } +#if GPU_SAFETY +static bool in_framebuffer_texture_bind = false; +#endif + void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, int w, int h) { +#if GPU_SAFETY + GPU_ASSERT(!in_frambuffer_texture_bind); + in_framebuffer_texture_bind = true; +#endif + + if (GG.extdisabled) + return; + /* push attributes */ glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT); glDisable(GL_SCISSOR_TEST); /* bind framebuffer */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object); + gpu_glBindFramebuffer(GL_FRAMEBUFFER_EXT, tex->fb->object); /* push matrices and set default viewport and matrix */ glViewport(0, 0, w, h); @@ -966,6 +1100,14 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, i void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex)) { +#if GPU_SAFETY + GPU_ASSERT(!in_frambuffer_texture_bind); + in_framebuffer_texture_bind = true; +#endif + + if (GG.extdisabled) + return; + /* restore matrix */ glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -979,16 +1121,19 @@ void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUS void GPU_framebuffer_free(GPUFrameBuffer *fb) { + if (GG.extdisabled) + return; + 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); + gpu_glDeleteFramebuffers(1, &fb->object); if (GG.currentfb == fb->object) { - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + gpu_glBindFramebuffer(GL_FRAMEBUFFER, 0); GG.currentfb = 0; } } @@ -998,73 +1143,76 @@ void GPU_framebuffer_free(GPUFrameBuffer *fb) void GPU_framebuffer_restore(void) { - if (GG.currentfb != 0) { - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + if (!GG.extdisabled && GG.currentfb != 0) { + gpu_glBindFramebuffer(GL_FRAMEBUFFER, 0); GG.currentfb = 0; } } void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *blurfb, GPUTexture *blurtex) { - float scaleh[2] = {1.0f/GPU_texture_opengl_width(blurtex), 0.0f}; - float scalev[2] = {0.0f, 1.0f/GPU_texture_opengl_height(tex)}; + if (!GG.extdisabled) { + float scaleh[2] = {1.0f/GPU_texture_opengl_width(blurtex), 0.0f}; + float scalev[2] = {0.0f, 1.0f/GPU_texture_opengl_height(tex)}; - GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR); - int scale_uniform, texture_source_uniform; + GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR); + int scale_uniform, texture_source_uniform; - if (!blur_shader) - return; - scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU"); - texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource"); - - /* Blurring horizontally */ - - /* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid - * pushing unnecessary matrices onto the OpenGL stack. */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blurfb->object); - - GPU_shader_bind(blur_shader); - GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scaleh); - GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex); - glViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex)); - - /* Peparing to draw quad */ - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + if (!blur_shader) + return; - glDisable(GL_DEPTH_TEST); - - GPU_texture_bind(tex, 0); - - /* Drawing quad */ - glBegin(GL_QUADS); - glTexCoord2d(0, 0); glVertex2f(1, 1); - glTexCoord2d(1, 0); glVertex2f(-1, 1); - glTexCoord2d(1, 1); glVertex2f(-1, -1); - glTexCoord2d(0, 1); glVertex2f(1, -1); - glEnd(); + scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU"); + texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource"); + + /* Blurring horizontally */ + + /* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid + * pushing unnecessary matrices onto the OpenGL stack. */ + gpu_glBindFramebuffer(GL_FRAMEBUFFER, blurfb->object); + + GPU_shader_bind(blur_shader); + GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scaleh); + GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex); + glViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex)); + + /* Peparing to draw quad */ + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); // make sure last current matrix is MODELVIEW + glLoadIdentity(); + + glDisable(GL_DEPTH_TEST); + + GPU_texture_bind(tex, 0); + + /* Drawing quad */ + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(0, 0); glVertex2f( 1, 1); + glTexCoord2d(1, 0); glVertex2f(-1, 1); + glTexCoord2d(1, 1); glVertex2f(-1, -1); + glTexCoord2d(0, 1); glVertex2f( 1, -1); + glEnd(); - /* Blurring vertically */ + /* Blurring vertically */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object); - glViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex)); - GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scalev); - GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex); - GPU_texture_bind(blurtex, 0); + gpu_glBindFramebuffer(GL_FRAMEBUFFER, fb->object); + glViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex)); + GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scalev); + GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex); + GPU_texture_bind(blurtex, 0); - glBegin(GL_QUADS); - glTexCoord2d(0, 0); glVertex2f(1, 1); - glTexCoord2d(1, 0); glVertex2f(-1, 1); - glTexCoord2d(1, 1); glVertex2f(-1, -1); - glTexCoord2d(0, 1); glVertex2f(1, -1); - glEnd(); + glBegin(GL_TRIANGLE_FAN); + glTexCoord2d(0, 0); glVertex2f( 1, 1); + glTexCoord2d(1, 0); glVertex2f(-1, 1); + glTexCoord2d(1, 1); glVertex2f(-1, -1); + glTexCoord2d(0, 1); glVertex2f( 1, -1); + glEnd(); - GPU_shader_unbind(); + GPU_shader_unbind(); + } } /* GPUOffScreen */ @@ -1083,7 +1231,7 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]) { GPUOffScreen *ofs; - ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen"); + ofs= (GPUOffScreen*)MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen"); ofs->w= width; ofs->h= height; @@ -1160,42 +1308,79 @@ int GPU_offscreen_height(GPUOffScreen *ofs) return ofs->h; } -/* GPUShader */ +static void shader_print_log(GLuint object, GLboolean is_program, const char* nickname, const char* kind) +{ + char* log; + GLint log_size = 0; -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 */ -}; + GPU_CHECK_NO_ERROR(); + + if (is_program) + gpu_glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_size); + else + gpu_glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_size); + + if (log_size > 0) { + log = (char*)MEM_mallocN(log_size, "shader_print_log"); + + if (is_program) + gpu_glGetProgramInfoLog(object, log_size, NULL, log); + else + gpu_glGetShaderInfoLog(object, log_size, NULL, log); + + if (is_program) + fprintf(stderr, "Linker Info Log:\n%s\n", log); + else + fprintf(stderr, "%s Shader: %s\nShader Info Log:\n%s\n", kind, nickname, log); -static void shader_print_errors(const char *task, char *log, const char **code, int totcode) + MEM_freeN(log); + } + + GPU_CHECK_NO_ERROR(); +} + +static void shader_print_errors(GLuint object, GLboolean is_program, const char* nickname, const char *kind, const char **code, int code_count) { - int i; + int total_line = 1; - fprintf(stderr, "GPUShader: %s error:\n", task); + if (G.debug & G_DEBUG) { + int i = 0; + + fprintf(stderr, "Source Code: %s\n", nickname); - for (i = 0; i < totcode; i++) { - const char *c, *pos, *end = code[i] + strlen(code[i]); - int line = 1; - - if (G.debug & G_DEBUG) { - fprintf(stderr, "===== shader string %d ====\n", i + 1); + for (i = 0; i < code_count; i++) { + const char *c= code[i]; + const char *pos; + const char *end = code[i] + strlen(code[i]); + int line = 1; - c = code[i]; while ((c < end) && (pos = strchr(c, '\n'))) { - fprintf(stderr, "%2d ", line); + fprintf(stderr, "%d:%3d:%3d: ", i, line, total_line); fwrite(c, (pos+1)-c, 1, stderr); c = pos+1; line++; + total_line++; } - + fprintf(stderr, "%s", c); } } - - fprintf(stderr, "%s\n", log); + + shader_print_log(object, is_program, nickname, kind); +} + +static bool print_status(GLuint object, GLboolean is_program, const char* nickname, const char* kind, const char** code, int code_count) +{ + GLint status; + + if (is_program) + gpu_glGetProgramiv(object, GL_LINK_STATUS, &status); + else + gpu_glGetShaderiv (object, GL_COMPILE_STATUS, &status); + + shader_print_errors(object, is_program, nickname, kind, code, code_count); + + return status; } static const char *gpu_shader_version(void) @@ -1238,24 +1423,54 @@ static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH]) return; } -GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines) +GPUShader *GPU_shader_create(const char* nickname, const char *vertexcode, const char *fragcode, const char *libcode, const char *defines) { GLint status; - GLcharARB log[5000]; - GLsizei length = 0; GPUShader *shader; char standard_defines[MAX_DEFINE_LENGTH] = ""; +#if 0 + int i; - if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) + /* XXX jwilkins: not sure if this belongs here. */ + /* This would not really be needed except that ATI cards seem to + have a bug where they don't recognize VertexAttrib when the attribute location is 0 */ + static struct AttribMap { + const GLchar* name; + GLuint index; + } attrib_map[] = { + { "b_Vertex", 1 }, + { "b_Color", 2 }, + { "b_Normal", 3 }, + { "b_MultiTexCoord0", 4 }, + { "b_MultiTexCoord1", 5 }, + { "b_MultiTexCoord2", 6 }, + { "b_MultiTexCoord3", 7 }, + { "b_MultiTexCoord4", 8 }, + { "b_MultiTexCoord5", 9 }, + { "b_MultiTexCoord6", 10 }, + { "b_MultiTexCoord7", 11 }, + }; +#endif + + if (GG.extdisabled || !GG.glslsupport) { return NULL; + } - shader = MEM_callocN(sizeof(GPUShader), "GPUShader"); + shader = (GPUShader*)MEM_callocN(sizeof(GPUShader), "GPUShader"); if (vertexcode) - shader->vertex = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); + shader->vertex = gpu_glCreateShader(GL_VERTEX_SHADER); + if (fragcode) - shader->fragment = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); - shader->object = glCreateProgramObjectARB(); + shader->fragment = gpu_glCreateShader(GL_FRAGMENT_SHADER); + + shader->object = gpu_glCreateProgram(); + +#if 0 + /* bind common attribute locations. has to be done before program is linked */ + for (i = 0; i < sizeof(attrib_map)/sizeof(struct AttribMap); i++) + gpu_glBindAttribLocation(shader->object, attrib_map[i].index, attrib_map[i].name); +#endif if (!shader->object || (vertexcode && !shader->vertex) || @@ -1277,19 +1492,15 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const source[num_source++] = gpu_shader_standard_extensions(); source[num_source++] = standard_defines; - if (defines) source[num_source++] = defines; + if (defines) source[num_source++] = defines; if (vertexcode) source[num_source++] = vertexcode; - glAttachObjectARB(shader->object, shader->vertex); - glShaderSourceARB(shader->vertex, num_source, source, NULL); + gpu_glAttachShader(shader->object, shader->vertex); + gpu_glShaderSource(shader->vertex, num_source, source, NULL); - glCompileShaderARB(shader->vertex); - glGetObjectParameterivARB(shader->vertex, GL_OBJECT_COMPILE_STATUS_ARB, &status); - - if (!status) { - glGetInfoLogARB(shader->vertex, sizeof(log), &length, log); - shader_print_errors("compile", log, source, num_source); + gpu_glCompileShader(shader->vertex); + if (!print_status(shader->vertex, GL_FALSE, nickname, "Vertex", source, num_source)) { GPU_shader_free(shader); return NULL; } @@ -1303,20 +1514,16 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const source[num_source++] = gpu_shader_standard_extensions(); source[num_source++] = standard_defines; - if (defines) source[num_source++] = defines; - if (libcode) source[num_source++] = libcode; + if (defines) source[num_source++] = defines; + if (libcode) source[num_source++] = libcode; if (fragcode) source[num_source++] = fragcode; - glAttachObjectARB(shader->object, shader->fragment); - glShaderSourceARB(shader->fragment, num_source, source, NULL); - - glCompileShaderARB(shader->fragment); - glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status); + gpu_glAttachShader(shader->object, shader->fragment); + gpu_glShaderSource(shader->fragment, num_source, source, NULL); - if (!status) { - glGetInfoLogARB(shader->fragment, sizeof(log), &length, log); - shader_print_errors("compile", log, source, num_source); + gpu_glCompileShader(shader->fragment); + if (!print_status(shader->fragment, GL_FALSE, nickname, "Fragment", source, num_source)) { GPU_shader_free(shader); return NULL; } @@ -1324,17 +1531,13 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const #if 0 if (lib && lib->lib) - glAttachObjectARB(shader->object, lib->lib); + gpuAttachShader(shader->object, lib->lib); #endif - glLinkProgramARB(shader->object); - glGetObjectParameterivARB(shader->object, GL_OBJECT_LINK_STATUS_ARB, &status); - if (!status) { - glGetInfoLogARB(shader->object, sizeof(log), &length, log); - if (fragcode) shader_print_errors("linking", log, &fragcode, 1); - else if (vertexcode) shader_print_errors("linking", log, &vertexcode, 1); - else if (libcode) shader_print_errors("linking", log, &libcode, 1); + gpu_glLinkProgram(shader->object); + gpu_glGetProgramiv(shader->object, GL_LINK_STATUS, &status); + if (!print_status(shader->object, GL_TRUE, nickname, NULL, NULL, 0)) { GPU_shader_free(shader); return NULL; } @@ -1346,11 +1549,10 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const 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) + if (GG.extdisabled || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) return NULL; shader = MEM_callocN(sizeof(GPUShader), "GPUShader"); @@ -1369,8 +1571,7 @@ GPUShader *GPU_shader_create_lib(const char *code) glGetObjectParameterivARB(shader->lib, GL_OBJECT_COMPILE_STATUS_ARB, &status); if (!status) { - glGetInfoLogARB(shader->lib, sizeof(log), &length, log); - shader_print_errors("compile", log, code); + shader_print_errors(shader->lib, GL_FALSE, "compile", (const char**)&code, 1); GPU_shader_free(shader); return NULL; @@ -1382,60 +1583,76 @@ GPUShader *GPU_shader_create_lib(const char *code) void GPU_shader_bind(GPUShader *shader) { + if (GG.extdisabled) + return; + GPU_print_error("Pre Shader Bind"); - glUseProgramObjectARB(shader->object); + gpu_glUseProgram(shader->object); GPU_print_error("Post Shader Bind"); } void GPU_shader_unbind(void) { + if (GG.extdisabled) + return; + GPU_print_error("Pre Shader Unbind"); - glUseProgramObjectARB(0); + gpu_glUseProgram(0); GPU_print_error("Post Shader Unbind"); } void GPU_shader_free(GPUShader *shader) { + if (GG.extdisabled) + return; + if (shader == NULL) + return; if (shader->lib) - glDeleteObjectARB(shader->lib); + gpu_glDeleteShader(shader->lib); if (shader->vertex) - glDeleteObjectARB(shader->vertex); + gpu_glDeleteShader(shader->vertex); if (shader->fragment) - glDeleteObjectARB(shader->fragment); + gpu_glDeleteShader(shader->fragment); if (shader->object) - glDeleteObjectARB(shader->object); + gpu_glDeleteProgram(shader->object); MEM_freeN(shader); } int GPU_shader_get_uniform(GPUShader *shader, const char *name) { - return glGetUniformLocationARB(shader->object, name); + return GG.extdisabled ? -1 : gpu_glGetUniformLocation(shader->object, name); } void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, float *value) { + if (GG.extdisabled) + return; + 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); + if (length == 1) gpu_glUniform1fv (location, arraysize, value); + else if (length == 2) gpu_glUniform2fv (location, arraysize, value); + else if (length == 3) gpu_glUniform3fv (location, arraysize, value); + else if (length == 4) gpu_glUniform4fv (location, arraysize, value); + else if (length == 9) gpu_glUniformMatrix3fv(location, arraysize, 0, value); + else if (length == 16) gpu_glUniformMatrix4fv(location, arraysize, 0, value); GPU_print_error("Post Uniform Vector"); } void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value) { + if (GG.extdisabled) + return; + if (location == -1) return; GPU_print_error("Pre Uniform Int"); - glUniform1iARB(location, value); + gpu_glUniform1i(location, value); GPU_print_error("Post Uniform Int"); } @@ -1443,11 +1660,14 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText { GLenum arbnumber; - if (tex->number >= GG.maxtextures) { - GPU_print_error("Not enough texture slots."); + if (GG.extdisabled) + return; + + if (tex->number >= GG.maxtextures && (G.debug & G_DEBUG)) { + fprintf(stderr, "Not enough texture slots."); return; } - + if (tex->number == -1) return; @@ -1456,16 +1676,22 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText GPU_print_error("Pre Uniform Texture"); - arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); + arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); + + if (tex->number != 0) + glActiveTexture(arbnumber); - if (tex->number != 0) glActiveTextureARB(arbnumber); if (tex->bindcode != 0) glBindTexture(tex->target, tex->bindcode); else GPU_invalid_tex_bind(tex->target); - glUniform1iARB(location, tex->number); + + gpu_glUniform1i(location, tex->number); + glEnable(tex->target); - if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB); + + if (tex->number != 0) + glActiveTexture(GL_TEXTURE0); GPU_print_error("Post Uniform Texture"); } @@ -1473,11 +1699,12 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText int GPU_shader_get_attribute(GPUShader *shader, const char *name) { int index; - - GPU_print_error("Pre Get Attribute"); - index = glGetAttribLocationARB(shader->object, name); + if (GG.extdisabled) + return -1; + GPU_print_error("Pre Get Attribute"); + index = gpu_glGetAttribLocation(shader->object, name); GPU_print_error("Post Get Attribute"); return index; @@ -1490,12 +1717,12 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader) switch (shader) { case GPU_SHADER_VSM_STORE: if (!GG.shaders.vsm_store) - GG.shaders.vsm_store = GPU_shader_create(datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL, NULL); + GG.shaders.vsm_store = GPU_shader_create("Built-in VSM", datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL, NULL); retval = GG.shaders.vsm_store; break; case GPU_SHADER_SEP_GAUSSIAN_BLUR: if (!GG.shaders.sep_gaussian_blur) - GG.shaders.sep_gaussian_blur = GPU_shader_create(datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL, NULL); + GG.shaders.sep_gaussian_blur = GPU_shader_create("Built-in Guassian Blur", datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL, NULL); retval = GG.shaders.sep_gaussian_blur; break; } @@ -1519,7 +1746,6 @@ void GPU_shader_free_builtin_shaders(void) } } -#if 0 /* GPUPixelBuffer */ typedef struct GPUPixelBuffer { @@ -1533,7 +1759,7 @@ typedef struct GPUPixelBuffer { void GPU_pixelbuffer_free(GPUPixelBuffer *pb) { if (pb->bindcode[0]) - glDeleteBuffersARB(pb->numbuffers, pb->bindcode); + gpu_glDeleteBuffers(pb->numbuffers, pb->bindcode); MEM_freeN(pb); } @@ -1541,15 +1767,15 @@ GPUPixelBuffer *gpu_pixelbuffer_create(int x, int y, int halffloat, int numbuffe { GPUPixelBuffer *pb; - if (!GLEW_ARB_multitexture || !GLEW_EXT_pixel_buffer_object) + if (GG.extdisabled || !GLEW_ARB_multitexture || !GLEW_EXT_pixel_buffer_object) return NULL; - pb = MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO"); + pb = (GPUPixelBuffer*)MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO"); pb->datasize = x*y*4*((halffloat)? 16: 8); pb->numbuffers = numbuffers; pb->halffloat = halffloat; - glGenBuffersARB(pb->numbuffers, pb->bindcode); + gpu_glGenBuffers(pb->numbuffers, pb->bindcode); if (!pb->bindcode[0]) { fprintf(stderr, "GPUPixelBuffer allocation failed\n"); @@ -1565,53 +1791,53 @@ void GPU_pixelbuffer_texture(GPUTexture *tex, GPUPixelBuffer *pb) void *pixels; int i; - glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode); + glBindTexture(GL_TEXTURE_RECTANGLE, 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); + gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pb->bindcode[pb->current]); + gpu_glBufferData(GL_PIXEL_UNPACK_BUFFER, pb->datasize, NULL, GL_STREAM_DRAW); - pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY); + pixels = gpu_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); /*memcpy(pixels, _oImage.data(), pb->datasize);*/ - if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) { + if (!gpu_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER)) { fprintf(stderr, "Could not unmap opengl PBO\n"); break; } } - glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0); + glBindTexture(GL_TEXTURE_RECTANGLE, 0); } -static int pixelbuffer_map_into_gpu(GLuint bindcode) +static bool 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); + gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bindcode); + pixels = gpu_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); /* do stuff in pixels */ - if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) { + if (!gpu_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER)) { fprintf(stderr, "Could not unmap opengl PBO\n"); - return 0; + return false; + } + else { + return true; } - - 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); + glBindTexture(GL_TEXTURE_RECTANGLE, tex->bindcode); + gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bindcode); - glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h, + glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, tex->w, tex->h, GL_RGBA, type, NULL); - glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); - glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0); + gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + glBindTexture(GL_TEXTURE_RECTANGLE, 0); } void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb) @@ -1630,5 +1856,418 @@ void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb) pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[pb->current]); } } + +#if GPU_SAFETY + +#define GPU_CHECK_INVALID_PNAME(symbol) \ + { \ + GLboolean paramOK; \ + GPU_SAFE_RETURN(pname != (symbol), paramOK,); \ + } + +#else + +#define GPU_CHECK_INVALID_PNAME(symbol) + +#endif + + +#if !defined(GLEW_ES_ONLY) +static void GLAPIENTRY check_glGetObjectParameterivARB(GLuint shader, GLuint pname, GLint *params) +{ + GPU_CHECK_INVALID_PNAME(GL_SHADER_TYPE); + + glGetObjectParameterivARB(shader, pname, params); +} +#endif + +static void GLAPIENTRY check_glGetShaderiv(GLuint shader, GLuint pname, GLint *params) +{ + GPU_CHECK_INVALID_PNAME(GL_SHADER_TYPE); + + glGetShaderiv(shader, pname, params); +} + +static GLboolean init_shader_objects(void) +{ + if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0) { + gpu_glAttachShader = glAttachShader; + gpu_glCompileShader = glCompileShader; + gpu_glCreateProgram = glCreateProgram; + gpu_glCreateShader = glCreateShader; + gpu_glDeleteShader = glDeleteShader; + gpu_glGetProgramInfoLog = glGetProgramInfoLog; + gpu_glGetShaderiv = check_glGetShaderiv; + gpu_glGetShaderInfoLog = glGetShaderInfoLog; + gpu_glGetUniformLocation = glGetUniformLocation; + gpu_glLinkProgram = glLinkProgram; + gpu_glShaderSource = glShaderSource; + gpu_glUniform1i = glUniform1i; + gpu_glUniform1f = glUniform1f; + gpu_glUniform1iv = glUniform1iv; + gpu_glUniform2iv = glUniform2iv; + gpu_glUniform3iv = glUniform3iv; + gpu_glUniform4iv = glUniform4iv; + gpu_glUniform1fv = glUniform1fv; + gpu_glUniform2fv = glUniform2fv; + gpu_glUniform3fv = glUniform3fv; + gpu_glUniform4fv = glUniform4fv; + gpu_glUniformMatrix3fv = glUniformMatrix3fv; + gpu_glUniformMatrix4fv = glUniformMatrix4fv; + gpu_glUseProgram = glUseProgram; + gpu_glValidateProgram = glValidateProgram; + + return GL_TRUE; + } + +#if !defined(GLEW_ES_ONLY) + if (GLEW_ARB_shader_objects) { + gpu_glAttachShader = glAttachObjectARB; + gpu_glCompileShader = glCompileShaderARB; + gpu_glCreateProgram = glCreateProgramObjectARB; + gpu_glCreateShader = glCreateShaderObjectARB; + gpu_glDeleteShader = glDeleteObjectARB; + gpu_glGetProgramInfoLog = glGetInfoLogARB; + gpu_glGetShaderiv = check_glGetObjectParameterivARB; + gpu_glGetShaderInfoLog = glGetInfoLogARB; + gpu_glGetUniformLocation = glGetUniformLocationARB; + gpu_glLinkProgram = glLinkProgramARB; + gpu_glShaderSource = glShaderSourceARB; + gpu_glUniform1i = glUniform1iARB; + gpu_glUniform1f = glUniform1fARB; + gpu_glUniform1iv = glUniform1ivARB; + gpu_glUniform2iv = glUniform2ivARB; + gpu_glUniform3iv = glUniform3ivARB; + gpu_glUniform4iv = glUniform4ivARB; + gpu_glUniform1fv = glUniform1fvARB; + gpu_glUniform2fv = glUniform2fvARB; + gpu_glUniform3fv = glUniform3fvARB; + gpu_glUniform4fv = glUniform4fvARB; + gpu_glUniformMatrix3fv = glUniformMatrix3fvARB; + gpu_glUniformMatrix4fv = glUniformMatrix4fvARB; + gpu_glUseProgram = glUseProgramObjectARB; + gpu_glValidateProgram = glValidateProgramARB; + + return GL_TRUE; + } +#endif + + return GL_FALSE; +} + +static GLboolean init_vertex_shader(void) +{ + if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0) { + gpu_glGetAttribLocation = glGetAttribLocation; + gpu_glBindAttribLocation = glBindAttribLocation; + + return GL_TRUE; + } + +#if !defined(GLEW_ES_ONLY) + if (GLEW_ARB_vertex_shader) { + gpu_glBindAttribLocation = (void (GLAPIENTRY*)(GLuint,GLuint,const GLchar*))glBindAttribLocationARB; + gpu_glGetAttribLocation = glGetAttribLocationARB; + + return GL_TRUE; + } +#endif + + return GL_FALSE; +} + +#if !defined(GLEW_ES_ONLY) +static void GLAPIENTRY check_glGetProgramivARB(GLuint shader, GLuint pname, GLint *params) +{ + GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTES); + GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH); + + glGetProgramivARB(shader, pname, params); +} #endif +static void GLAPIENTRY check_glGetProgramiv(GLuint shader, GLuint pname, GLint *params) +{ + GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTES); + GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH); + + glGetProgramiv(shader, pname, params); +} + +static GLboolean init_vertex_program(void) +{ + if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0) { + gpu_glDeleteProgram = glDeleteProgram; + gpu_glDisableVertexAttribArray = glDisableVertexAttribArray; + gpu_glEnableVertexAttribArray = glEnableVertexAttribArray; + gpu_glGetProgramiv = check_glGetProgramiv; + gpu_glVertexAttribPointer = glVertexAttribPointer; + + return GL_TRUE; + } + +#if !defined(GLEW_ES_ONLY) + if (GLEW_ARB_vertex_program) { + gpu_glDeleteProgram = glDeleteObjectARB; + gpu_glDisableVertexAttribArray = glDisableVertexAttribArrayARB; + gpu_glEnableVertexAttribArray = glEnableVertexAttribArrayARB; + gpu_glGetProgramiv = check_glGetProgramivARB; + gpu_glVertexAttribPointer = glVertexAttribPointerARB; + + return GL_TRUE; + } +#endif + + return GL_FALSE; +} + +static void init_buffers(void) +{ + if (GLEW_VERSION_1_5 || GLEW_ES_VERSION_2_0) { + gpu_glBindBuffer = glBindBuffer; + gpu_glBufferData = glBufferData; + gpu_glBufferSubData = glBufferSubData; + gpu_glDeleteBuffers = glDeleteBuffers; + gpu_glGenBuffers = glGenBuffers; + + return; + } + +#if !defined(GLEW_ES_ONLY) + if (GLEW_ARB_vertex_buffer_object) { + gpu_glBindBuffer = glBindBufferARB; + gpu_glBufferData = glBufferDataARB; + gpu_glBufferSubData = glBufferSubDataARB; + gpu_glDeleteBuffers = glDeleteBuffersARB; + gpu_glGenBuffers = glGenBuffersARB; + + return; + } +#endif +} + +static void init_mapbuffer(void) +{ +#if !defined(GLEW_ES_ONLY) + if (GLEW_VERSION_1_5) { + gpu_glMapBuffer = glMapBuffer; + gpu_glUnmapBuffer = glUnmapBuffer; + + return; + } + + if (GLEW_ARB_vertex_buffer_object) { + gpu_glMapBuffer = glMapBufferARB; + gpu_glUnmapBuffer = glUnmapBufferARB; + + return; + } +#endif + +#if !defined(GLEW_NO_ES) + if (GLEW_OES_mapbuffer) { + gpu_glMapBuffer = glMapBufferOES; + gpu_glUnmapBuffer = glUnmapBufferOES; + + return; + } +#endif +} + +static GLboolean init_framebuffer_object(void) +{ + if (GLEW_VERSION_3_0 || GLEW_ES_VERSION_2_0 || GLEW_ARB_framebuffer_object) { + gpu_glGenFramebuffers = glGenFramebuffers; + gpu_glBindFramebuffer = glBindFramebuffer; + gpu_glDeleteFramebuffers = glDeleteFramebuffers; + gpu_glFramebufferTexture2D = glFramebufferTexture2D; + gpu_glCheckFramebufferStatus = glCheckFramebufferStatus; + + return GL_TRUE; + } + +#if !defined(GLEW_ES_ONLY) + if (GLEW_EXT_framebuffer_object) { + gpu_glGenFramebuffers = glGenFramebuffersEXT; + gpu_glBindFramebuffer = glBindFramebufferEXT; + gpu_glDeleteFramebuffers = glDeleteFramebuffersEXT; + gpu_glFramebufferTexture2D = glFramebufferTexture2DEXT; + gpu_glCheckFramebufferStatus = glCheckFramebufferStatusEXT; + + return GL_TRUE; + } +#endif + +#if !defined(GLEW_NO_ES) + if (GLEW_OES_framebuffer_object) { + gpu_glGenFramebuffers = glGenFramebuffersOES; + gpu_glBindFramebuffer = glBindFramebufferOES; + gpu_glDeleteFramebuffers = glDeleteFramebuffersOES; + gpu_glFramebufferTexture2D = glFramebufferTexture2DOES; + gpu_glCheckFramebufferStatus = glCheckFramebufferStatusOES; + + return GL_TRUE; + } +#endif + + return GL_FALSE; +} + +static void init_vertex_arrays(void) +{ +#if !defined(GLEW_ES_ONLY) + if (GLEW_VERSION_3_0 || GLEW_ARB_vertex_array_object) { + gpu_glGenVertexArrays = glGenVertexArrays; + gpu_glBindVertexArray = glBindVertexArray; + gpu_glDeleteVertexArrays = glDeleteVertexArrays; + + return; + } +#endif + +#if !defined(GLEW_NO_ES) + if (GLEW_OES_vertex_array_object) { + gpu_glGenVertexArrays = glGenVertexArraysOES; + gpu_glBindVertexArray = glBindVertexArrayOES; + gpu_glDeleteVertexArrays = glDeleteVertexArraysOES; + + return; + } +#endif +} + +static GPUFUNC void (GLAPIENTRY* _GenerateMipmap)(GLenum target); + +static void init_generate_mipmap(void) +{ +#if !defined(GLEW_ES_ONLY) + if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object) { + _GenerateMipmap = glGenerateMipmap; + return; + } + + if (GLEW_EXT_framebuffer_object) { + _GenerateMipmap = glGenerateMipmapEXT; + return; + } +#endif + +#if !defined(GLEW_NO_ES) + if (GLEW_OES_framebuffer_object) { + _GenerateMipmap = glGenerateMipmapOES; + } +#endif +} + +void gpu_glGenerateMipmap(GLenum target) +{ + GLboolean workaround; + + /* Work around bug in ATI driver, need to have GL_TEXTURE_2D enabled. + * http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation */ + if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) { + workaround = !glIsEnabled(target); + + if (workaround) { + glEnable(target); + } + } + else { + workaround = GL_FALSE; + } + + _GenerateMipmap(target); + + if (workaround) { + glDisable(target); + } +} + +static void* gpu_buffer_start_update_dummy(GLenum UNUSED(target), void* data) +{ + GPU_ASSERT(data != NULL); + return data; +} + +static void* gpu_buffer_start_update_copy(GLenum UNUSED(target), void* data) +{ + GPU_ASSERT(data != NULL); + return data; +} + +static void* gpu_buffer_start_update_map(GLenum target, void* UNUSED(data)) +{ + void* mappedData; + GPU_ASSERT(UNUSED_data == NULL); + mappedData = gpu_glMapBuffer(target, GL_WRITE_ONLY); + GPU_CHECK_NO_ERROR(); + return mappedData; +} + +static void gpu_buffer_finish_update_dummy(GLenum UNUSED(target), GLsizeiptr UNUSED(dataSize), const GLvoid* UNUSED(data)) +{ + GPU_ASSERT(UNUSED_data != NULL); +} + +static void gpu_buffer_finish_update_copy(GLenum target, GLsizeiptr dataSize, const GLvoid* data) +{ + GPU_ASSERT(data != NULL); + gpu_glBufferSubData(target, 0, dataSize, data); + GPU_CHECK_NO_ERROR(); +} + +static void gpu_buffer_finish_update_map(GLenum target, GLsizeiptr UNUSED(dataSize), const GLvoid* UNUSED(data)) +{ + GPU_ASSERT(UNUSED_data != NULL); + gpu_glUnmapBuffer(target); + GPU_CHECK_NO_ERROR(); +} + + + +static void shim_init(void) +{ + if (!GG.extdisabled) { + GG.glslsupport = true; + + if (!init_shader_objects()) + GG.glslsupport = false; + + if (!init_vertex_shader()) + GG.glslsupport = false; + + if (!init_vertex_program()) + GG.glslsupport = false; + + if (!(GLEW_ARB_multitexture || GLEW_VERSION_1_3 || GLEW_ES_VERSION_2_0)) // Note: This should mean only the non-deprecated parts of the multitexture extension + GG.glslsupport = false; + + GG.framebuffersupport = init_framebuffer_object(); + + init_vertex_arrays(); + init_buffers(); + init_mapbuffer(); + + if (GLEW_VERSION_1_5 || GLEW_OES_mapbuffer || GLEW_ARB_vertex_buffer_object) { + gpu_buffer_start_update = gpu_buffer_start_update_map; + gpu_buffer_finish_update = gpu_buffer_finish_update_map; + } + else if (GLEW_ES_VERSION_2_0) { + gpu_buffer_start_update = gpu_buffer_start_update_copy; + gpu_buffer_finish_update = gpu_buffer_finish_update_copy; + } + else { + gpu_buffer_start_update = gpu_buffer_start_update_dummy; + gpu_buffer_finish_update = gpu_buffer_finish_update_dummy; + } + + init_generate_mipmap(); + } + else { + GG.glslsupport = false; + GG.framebuffersupport = false; + + gpu_buffer_start_update = gpu_buffer_start_update_dummy; + gpu_buffer_finish_update = gpu_buffer_finish_update_dummy; + } +} diff --git a/source/blender/gpu/intern/gpu_extensions_intern.h b/source/blender/gpu/intern/gpu_extensions_intern.h new file mode 100644 index 00000000000..bdaf211f29a --- /dev/null +++ b/source/blender/gpu/intern/gpu_extensions_intern.h @@ -0,0 +1,305 @@ +#ifndef _GPU_SHIM_H_ +#define _GPU_SHIM_H_ + +/* ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov, Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_shim.h + * \ingroup gpu + */ + +#include "GPU_glew.h" +#include "GPU_extensions.h" + +#ifndef GPU_FUNC_INTERN +#define GPUFUNC extern +#else +#define GPUFUNC +#endif + + +#undef GLAPIENTRY /* glew.h was included above, so GLAPIENTRY is defined, but blank */ + +/***** BEGIN:THIS CODE WAS COPIED DIRECTLY FROM glew.h *****/ + +#if defined(_WIN32) + +/* + * GLEW does not include <windows.h> to avoid name space pollution. + * GL needs GLAPI and GLAPIENTRY, GLU needs APIENTRY, CALLBACK, and wchar_t + * defined properly. + */ +/* <windef.h> */ +#ifndef APIENTRY +#define GLEW_APIENTRY_DEFINED +# if defined(__MINGW32__) || defined(__CYGWIN__) +# define APIENTRY __stdcall +# elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) +# define APIENTRY __stdcall +# else +# define APIENTRY +# endif +#endif +#ifndef GLAPI +# if defined(__MINGW32__) || defined(__CYGWIN__) +# define GLAPI extern +# endif +#endif +/* <winnt.h> */ +#ifndef CALLBACK +#define GLEW_CALLBACK_DEFINED +# if defined(__MINGW32__) || defined(__CYGWIN__) +# define CALLBACK __attribute__ ((__stdcall__)) +# elif (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) +# define CALLBACK __stdcall +# else +# define CALLBACK +# endif +#endif +/* <wingdi.h> and <winnt.h> */ +#ifndef WINGDIAPI +#define GLEW_WINGDIAPI_DEFINED +#define WINGDIAPI __declspec(dllimport) +#endif +/* <ctype.h> */ +#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(_WCHAR_T_DEFINED) +typedef unsigned short wchar_t; +# define _WCHAR_T_DEFINED +#endif +/* <stddef.h> */ +#if !defined(_W64) +# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && defined(_MSC_VER) && _MSC_VER >= 1300 +# define _W64 __w64 +# else +# define _W64 +# endif +#endif +#if !defined(_PTRDIFF_T_DEFINED) && !defined(_PTRDIFF_T_) && !defined(__MINGW64__) +# ifdef _WIN64 +typedef __int64 ptrdiff_t; +# else +typedef _W64 int ptrdiff_t; +# endif +# define _PTRDIFF_T_DEFINED +# define _PTRDIFF_T_ +#endif + +#ifndef GLAPI +# if defined(__MINGW32__) || defined(__CYGWIN__) +# define GLAPI extern +# else +# define GLAPI WINGDIAPI +# endif +#endif + +#ifndef GLAPIENTRY +#define GLAPIENTRY APIENTRY +#endif + +/* + * GLEW_STATIC is defined for static library. + * GLEW_BUILD is defined for building the DLL library. + */ + +#ifdef GLEW_STATIC +# define GLEWAPI extern +#else +# ifdef GLEW_BUILD +# define GLEWAPI extern __declspec(dllexport) +# else +# define GLEWAPI extern __declspec(dllimport) +# endif +#endif + +#else /* _UNIX */ + +/* + * Needed for ptrdiff_t in turn needed by VBO. This is defined by ISO + * C. On my system, this amounts to _3 lines_ of included code, all of + * them pretty much harmless. If you know of a way of detecting 32 vs + * 64 _targets_ at compile time you are free to replace this with + * something that's portable. For now, _this_ is the portable solution. + * (mem, 2004-01-04) + */ + +#include <stddef.h> + +/* SGI MIPSPro doesn't like stdint.h in C++ mode */ +/* ID: 3376260 Solaris 9 has inttypes.h, but not stdint.h */ + +#if (defined(__sgi) || defined(__sun)) && !defined(__GNUC__) +#include <inttypes.h> +#else +#include <stdint.h> +#endif + +#define GLEW_APIENTRY_DEFINED +#define APIENTRY + +/* + * GLEW_STATIC is defined for static library. + */ + +#ifdef GLEW_STATIC +# define GLEWAPI extern +#else +# if defined(__GNUC__) && __GNUC__>=4 +# define GLEWAPI extern __attribute__ ((visibility("default"))) +# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +# define GLEWAPI extern __global +# else +# define GLEWAPI extern +# endif +#endif + +/* XXX jwilkins: assuming gcc compiling for android? also this got plopped in middle of verbatim code copied from glew... */ +#ifdef WITH_ANDROID +#undef GLEWAPI +# define GLEWAPI extern __attribute__ ((visibility("default"))) +#endif + +/* <glu.h> */ +#ifndef GLAPI +#define GLAPI extern +#endif +#ifndef GLAPIENTRY +#define GLAPIENTRY +#endif + +#endif /* _WIN32 */ + +/***** END:THIS CODE WAS COPIED DIRECTLY FROM glew.h *****/ + +#ifdef __cplusplus +extern "C" { +#endif + +GPUFUNC GLuint (GLAPIENTRY* gpu_glCreateShader)(GLuint shaderType); +GPUFUNC void (GLAPIENTRY* gpu_glAttachShader)(GLuint program, GLuint shader); +GPUFUNC void (GLAPIENTRY* gpu_glShaderSource)(GLuint shader, GLint count, const GLchar ** string, const GLint * length); +GPUFUNC void (GLAPIENTRY* gpu_glCompileShader)(GLuint shader); +GPUFUNC void (GLAPIENTRY* gpu_glGetShaderiv)(GLuint shader, GLuint pname, GLint *params); +GPUFUNC void (GLAPIENTRY* gpu_glGetShaderInfoLog)(GLuint shader, GLint maxLength, GLint *length, GLchar *infoLog); + +GPUFUNC GLuint (GLAPIENTRY* gpu_glCreateProgram)(void); +GPUFUNC void (GLAPIENTRY* gpu_glLinkProgram)(GLuint program); +GPUFUNC void (GLAPIENTRY* gpu_glGetProgramiv)(GLuint shader, GLuint pname, GLint *params); +GPUFUNC void (GLAPIENTRY* gpu_glGetProgramInfoLog)(GLuint shader, GLint maxLength, GLint *length, GLchar *infoLog); +GPUFUNC void (GLAPIENTRY* gpu_glValidateProgram)(GLuint program); + + +GPUFUNC void (GLAPIENTRY* gpu_glUniform1i)(GLint location, GLint v0); +GPUFUNC void (GLAPIENTRY* gpu_glUniform1f)(GLint location, GLfloat v0); + +GPUFUNC void (GLAPIENTRY* gpu_glUniform1iv)(GLint location, GLint count, const GLint * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniform2iv)(GLint location, GLint count, const GLint * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniform3iv)(GLint location, GLint count, const GLint * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniform4iv)(GLint location, GLint count, const GLint * value); + + +GPUFUNC void (GLAPIENTRY* gpu_glUniform1fv)(GLint location, GLint count, const GLfloat * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniform2fv)(GLint location, GLint count, const GLfloat * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniform3fv)(GLint location, GLint count, const GLfloat * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniform4fv)(GLint location, GLint count, const GLfloat * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniformMatrix3fv)(GLint location, GLint count, GLboolean transpose, const GLfloat * value); +GPUFUNC void (GLAPIENTRY* gpu_glUniformMatrix4fv)(GLint location, GLint count, GLboolean transpose, const GLfloat * value); + +GPUFUNC GLint (GLAPIENTRY* gpu_glGetAttribLocation )(GLuint program, const GLchar *name); +GPUFUNC void (GLAPIENTRY* gpu_glBindAttribLocation)(GLuint program, GLuint index, const GLchar * name); +GPUFUNC GLint (GLAPIENTRY* gpu_glGetUniformLocation)(GLuint program, const GLchar * name); + +GPUFUNC void (GLAPIENTRY* gpu_glVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); + +GPUFUNC void (GLAPIENTRY* gpu_glEnableVertexAttribArray)(GLuint index); +GPUFUNC void (GLAPIENTRY* gpu_glDisableVertexAttribArray)(GLuint index); + +GPUFUNC void (GLAPIENTRY* gpu_glUseProgram)(GLuint program); +GPUFUNC void (GLAPIENTRY* gpu_glDeleteShader)(GLuint shader); +GPUFUNC void (GLAPIENTRY* gpu_glDeleteProgram)(GLuint program); + + + +GPUFUNC void (GLAPIENTRY* gpu_glGenFramebuffers)(GLint m, GLuint * ids); +GPUFUNC void (GLAPIENTRY* gpu_glBindFramebuffer)(GLuint target, GLuint framebuffer); +GPUFUNC void (GLAPIENTRY* gpu_glDeleteFramebuffers)(GLint n, const GLuint * framebuffers); +GPUFUNC void (GLAPIENTRY* gpu_glFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GPUFUNC GLenum (GLAPIENTRY* gpu_glCheckFramebufferStatus)(GLenum target); + +GPUFUNC void (GLAPIENTRY* gpu_glGenBuffers)(GLsizei n, GLuint *buffers); +GPUFUNC void (GLAPIENTRY* gpu_glBindBuffer)(GLenum target, GLuint buffer); +GPUFUNC void (GLAPIENTRY* gpu_glBufferData)(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); +GPUFUNC void (GLAPIENTRY* gpu_glBufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); +GPUFUNC void (GLAPIENTRY* gpu_glDeleteBuffers)(GLsizei n, const GLuint * buffers); + +GPUFUNC void * (GLAPIENTRY* gpu_glMapBuffer)(GLenum target, GLenum access); +GPUFUNC GLboolean (GLAPIENTRY* gpu_glUnmapBuffer)(GLenum target); + +GPUFUNC void (GLAPIENTRY* gpu_glGenVertexArrays)(GLsizei n, GLuint *arrays); +GPUFUNC void (GLAPIENTRY* gpu_glBindVertexArray)(GLuint array); +GPUFUNC void (GLAPIENTRY* gpu_glDeleteVertexArrays)(GLsizei n, const GLuint *arrays); + +GPUFUNC void* (*gpu_buffer_start_update )(GLenum target, GLvoid* data); +GPUFUNC void (*gpu_buffer_finish_update)(GLenum target, GLsizeiptr size, const GLvoid* data); + +void gpu_glGenerateMipmap(GLenum target); + +void gpu_extensions_init(void); /* call this before running any of the functions below */ +void gpu_extensions_exit(void); + +#ifdef __cplusplus +} +#endif + + +//#ifndef GPU_FUNC_INTERN + +/***** BEGIN:THIS CODE WAS COPIED DIRECTLY FROM glew.h *****/ + +#ifdef GLEW_APIENTRY_DEFINED +#undef GLEW_APIENTRY_DEFINED +#undef APIENTRY +//#undef GLAPIENTRY +//#define GLAPIENTRY +#endif + +#ifdef GLEW_CALLBACK_DEFINED +#undef GLEW_CALLBACK_DEFINED +#undef CALLBACK +#endif + +#ifdef GLEW_WINGDIAPI_DEFINED +#undef GLEW_WINGDIAPI_DEFINED +#undef WINGDIAPI +#endif + +#undef GLAPI +/* #undef GLEWAPI */ + +/***** END:THIS CODE WAS COPIED DIRECTLY FROM glew.h *****/ + +//#endif + +#endif /* _GPU_SHIM_H_ */ diff --git a/source/blender/gpu/intern/gpu_font.c b/source/blender/gpu/intern/gpu_font.c new file mode 100644 index 00000000000..f355c9a72b4 --- /dev/null +++ b/source/blender/gpu/intern/gpu_font.c @@ -0,0 +1,210 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_font.c + * \ingroup gpu + */ + +/* my interface */ +#include "intern/gpu_font_intern.h" + +/* my library */ +#include "GPU_blender_aspect.h" +#include "GPU_extensions.h" +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_common_intern.h" +#include "intern/gpu_matrix_intern.h" + +/* external */ + +#include "BLI_dynstr.h" +#include "BLI_utildefines.h" + +#include "MEM_guardedalloc.h" + + + +static struct GPUShader* FONT_SHADER = NULL; +static struct GPUcommon FONT_COMMON = {0}; +static bool FONT_FAILED = false; + +#if GPU_SAFETY +static bool FONT_BEGUN = false; +#endif + + + +void gpu_font_init(void) +{ + FONT_SHADER = NULL; +} + + + +void gpu_font_exit(void) +{ + GPU_shader_free(FONT_SHADER); + +#if GPU_SAFETY + FONT_BEGUN = false; +#endif +} + + + +static void gpu_font_shader(void) +{ + /* GLSL code */ + extern const char datatoc_gpu_shader_font_vert_glsl[]; + extern const char datatoc_gpu_shader_font_frag_glsl[]; + + /* Create shader if it doesn't exist yet. */ + if (FONT_SHADER != NULL) { + GPU_shader_bind(FONT_SHADER); + gpu_set_common(&FONT_COMMON); + } + else if (!FONT_FAILED) { + DynStr* vert = BLI_dynstr_new(); + DynStr* frag = BLI_dynstr_new(); + DynStr* defs = BLI_dynstr_new(); + + char* vert_cstring; + char* frag_cstring; + char* defs_cstring; + + gpu_include_common_vert(vert); + BLI_dynstr_append(vert, datatoc_gpu_shader_font_vert_glsl); + + gpu_include_common_frag(frag); + BLI_dynstr_append(frag, datatoc_gpu_shader_font_frag_glsl); + + gpu_include_common_defs(defs); + BLI_dynstr_append(defs, "#define USE_TEXTURE_2D\n"); + + vert_cstring = BLI_dynstr_get_cstring(vert); + frag_cstring = BLI_dynstr_get_cstring(frag); + defs_cstring = BLI_dynstr_get_cstring(defs); + + FONT_SHADER = + GPU_shader_create("Font", vert_cstring, frag_cstring, NULL, defs_cstring); + + MEM_freeN(vert_cstring); + MEM_freeN(frag_cstring); + MEM_freeN(defs_cstring); + + BLI_dynstr_free(vert); + BLI_dynstr_free(frag); + BLI_dynstr_free(defs); + + if (FONT_SHADER != NULL) { + gpu_common_get_symbols(&FONT_COMMON, FONT_SHADER); + gpu_set_common(&FONT_COMMON); + + GPU_shader_bind(FONT_SHADER); + } + else { + FONT_FAILED = true; + gpu_set_common(NULL); + } + } + else { + gpu_set_common(NULL); + } +} + + + +/* Bind / Unbind */ + + + +void gpu_font_bind(void) +{ + bool glsl_support = GPU_glsl_support(); + + GPU_ASSERT(FONT_BEGUN); + + if (glsl_support) + gpu_font_shader(); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (!glsl_support) + GPU_CHECK(glEnable(GL_TEXTURE_2D)); +#endif + + gpu_commit_matrix(); +} + + + +void gpu_font_unbind(void) +{ + bool glsl_support = GPU_glsl_support(); + + GPU_ASSERT(FONT_BEGUN); + + if (glsl_support) + GPU_shader_unbind(); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (!glsl_support) + GPU_CHECK(glDisable(GL_TEXTURE_2D)); +#endif +} + + + +void GPU_font_begin(void) +{ +#if GPU_SAFETY + GPU_ASSERT(!FONT_BEGUN); + FONT_BEGUN = true; +#endif + + GPU_aspect_end(); /* assuming was GPU_ASPECT_BASIC */ + + GPU_aspect_begin(GPU_ASPECT_FONT, 0); +} + + + +void GPU_font_end(void) +{ +#if GPU_SAFETY + GPU_ASSERT(FONT_BEGUN); +#endif + + GPU_aspect_end(); + +#if GPU_SAFETY + FONT_BEGUN = false; +#endif + + GPU_aspect_begin(GPU_ASPECT_BASIC, 0); +} diff --git a/source/blender/gpu/intern/gpu_font_intern.h b/source/blender/gpu/intern/gpu_font_intern.h new file mode 100644 index 00000000000..28b72a49fb8 --- /dev/null +++ b/source/blender/gpu/intern/gpu_font_intern.h @@ -0,0 +1,51 @@ +#ifndef _GPU_FONT_INTERN_H_ +#define _GPU_FONT_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_font_intern.h + * \ingroup gpu + */ + +#include "GPU_font.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_font_init(void); +void gpu_font_exit(void); + +void gpu_font_bind (void); +void gpu_font_unbind(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c new file mode 100644 index 00000000000..7f5127408aa --- /dev/null +++ b/source/blender/gpu/intern/gpu_immediate.c @@ -0,0 +1,1665 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_immediate.c + * \ingroup gpu + */ + +/* my interface */ +#include "intern/gpu_immediate_intern.h" + +/* my library */ +#include "GPU_extensions.h" + +/* internal */ +#include "intern/gpu_profile.h" + +/* external */ +#include "MEM_guardedalloc.h" + +/* standard */ +#include <string.h> + + + +#if GPU_SAFETY + +/* Define some useful, but potentially slow, checks for correct API usage. */ + +/* Each block contains variables that can be inspected by a + debugger in the event that a break point is triggered. */ + +#define GPU_CHECK_CAN_SETUP() \ + { \ + GLboolean immediateOK; \ + GLboolean noLockOK; \ + GLboolean noBeginOK; \ + GPU_CHECK_BASE(immediateOK); \ + GPU_CHECK_NO_LOCK(noLockOK) \ + GPU_CHECK_NO_BEGIN(noBeginOK) \ + } + +#define GPU_CHECK_CAN_PUSH() \ + { \ + GLboolean immediateStackOK; \ + GLboolean noLockOK; \ + GLboolean noBeginOK; \ + GPU_SAFE_RETURN(immediateStack == NULL, immediateStackOK,); \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->mappedBuffer == NULL, noLockOK,); \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount == 0, noBeginOK,); \ + } + +#define GPU_CHECK_CAN_POP() \ + { \ + GLboolean immediateOK; \ + GLboolean noLockOK; \ + GLboolean noBeginOK; \ + GPU_SAFE_RETURN(GPU_IMMEDIATE != NULL, immediateOK, NULL); \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->mappedBuffer == NULL, noLockOK, NULL); \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount == 0, noBeginOK, NULL); \ + } + +#define GPU_CHECK_CAN_LOCK() \ + { \ + GLboolean immediateOK; \ + GLboolean noBeginOK; \ + GLboolean noLockOK; \ + GPU_CHECK_BASE(immediateOK); \ + GPU_CHECK_NO_BEGIN(noBeginOK); \ + GPU_CHECK_NO_LOCK(noLockOK); \ + } + +#define GPU_CHECK_CAN_UNLOCK() \ + { \ + GLboolean immediateOK; \ + GLboolean isLockedOK; \ + GLboolean noBeginOK; \ + GPU_CHECK_BASE(immediateOK); \ + GPU_CHECK_IS_LOCKED(isLockedOK) \ + GPU_CHECK_NO_BEGIN(noBeginOK) \ + } + +// XXX jwilkins: make this assert prettier +#define GPU_SAFE_STMT(var, test, stmt) \ + var = (GLboolean)(test); \ + GPU_ASSERT(((void)#test, var)); \ + if (var) { \ + stmt; \ + } + +#else + +#define GPU_CHECK_CAN_SETUP() +#define GPU_CHECK_CAN_PUSH() +#define GPU_CHECK_CAN_POP() +#define GPU_CHECK_CAN_LOCK() +#define GPU_CHECK_CAN_UNLOCK() + +#define GPU_CHECK_CAN_CURRENT() +#define GPU_CHECK_CAN_GET_COLOR() +#define GPU_CHECK_CAN_GET_NORMAL() + +#define GPU_SAFE_STMT(var, test, stmt) { (void)(var); stmt; } + +#endif + + + +/* global symbol needed because the immediate drawing functons are inline */ +GPUimmediate *__restrict GPU_IMMEDIATE = NULL; + + + +void gpuBegin(GLenum mode) +{ + int primMod; + int primOff; + + GPU_CHECK_CAN_BEGIN(); + +#if GPU_SAFETY + GPU_IMMEDIATE->hasOverflowed = GL_FALSE; +#endif + + GPU_IMMEDIATE->mode = mode; + GPU_IMMEDIATE->offset = 0; + GPU_IMMEDIATE->count = 0; + + switch (mode) { + case GL_LINES: + primMod = 2; + primOff = 0; + break; + + case GL_QUAD_STRIP: + case GL_TRIANGLE_STRIP: + primMod = 2; + primOff = 2; + break; + + case GL_TRIANGLES: + primMod = 3; + primOff = 0; + break; + + case GL_QUADS: + primMod = 4; + primOff = 2; + break; + + default: + primMod = 1; + primOff = 0; + break; + } + + GPU_IMMEDIATE->lastPrimVertex = GPU_IMMEDIATE->maxVertexCount - (GPU_IMMEDIATE->maxVertexCount % primMod); + + gpu_begin_buffer_gl(); +} + + + +void gpuEnd(void) +{ + GPU_CHECK_CAN_END(); + GPU_ASSERT(GPU_IMMEDIATE->mode != GL_NOOP || !(GPU_IMMEDIATE->hasOverflowed)); + + gpu_end_buffer_gl(); + + GPU_IMMEDIATE->mappedBuffer = NULL; +} + + + +void gpuImmediateFormatReset(void) +{ + /* reset vertex format */ + memset(&(GPU_IMMEDIATE->format), 0, sizeof(GPU_IMMEDIATE->format)); + GPU_IMMEDIATE->format.vertexSize = 3; +} + + + +void gpuImmediateLock(void) +{ + GPU_CHECK_CAN_LOCK(); + + if (GPU_IMMEDIATE->lockCount == 0) + gpu_lock_buffer_gl(); + + GPU_IMMEDIATE->lockCount++; +} + +void gpuImmediateUnlock(void) +{ + GPU_CHECK_CAN_UNLOCK(); + + GPU_IMMEDIATE->lockCount--; + + if (GPU_IMMEDIATE->lockCount == 0) + gpu_unlock_buffer_gl(); +} + + + +GLint gpuImmediateLockCount(void) +{ + GPU_ASSERT(GPU_IMMEDIATE); + + if (!GPU_IMMEDIATE) { + return GL_FALSE; + } + + return GPU_IMMEDIATE->lockCount; +} + + + +static void gpu_copy_vertex(void); + + + +GPUimmediate* gpuNewImmediate(void) +{ + GPUimmediate* immediate = + (GPUimmediate*)MEM_callocN(sizeof(GPUimmediate), "GPUimmediate"); + + immediate->copyVertex = gpu_copy_vertex; + +#if GPU_SAFETY + immediate->lastTexture = GPU_max_textures() - 1; +#endif + + return immediate; +} + + + +void gpuImmediateMakeCurrent(GPUimmediate *__restrict immediate) +{ + GPU_IMMEDIATE = immediate; +} + + + +void gpuDeleteImmediate(GPUimmediate *__restrict immediate) +{ + if (!immediate) + return; + + if (GPU_IMMEDIATE == immediate) + gpuImmediateMakeCurrent(NULL); + + gpu_shutdown_buffer_gl(immediate); + + MEM_freeN(immediate); +} + + + +void gpuImmediateElementSizes( + GLint vertexSize, + GLint normalSize, + GLint colorSize) +{ + GLboolean vertexOK; + GLboolean normalOK; + GLboolean colorOK; + + GPU_CHECK_CAN_SETUP(); + + GPU_SAFE_STMT( + vertexOK, + vertexSize > 0 && vertexSize <= 4, + GPU_IMMEDIATE->format.vertexSize = vertexSize); + + GPU_SAFE_STMT( + normalOK, + normalSize == 0 || normalSize == 3, + GPU_IMMEDIATE->format.normalSize = normalSize); + + GPU_SAFE_STMT( + colorOK, + colorSize == 0 || colorSize == 4, //-V112 + GPU_IMMEDIATE->format.colorSize = colorSize); +} + + + +void gpuImmediateMaxVertexCount(GLsizei maxVertexCount) +{ + GLboolean maxVertexCountOK; + + GPU_CHECK_CAN_SETUP(); + + GPU_SAFE_STMT( + maxVertexCountOK, + maxVertexCount >= 0, + GPU_IMMEDIATE->maxVertexCount = maxVertexCount); +} + + + +void gpuImmediateTexCoordCount(size_t count) +{ + GLboolean countOK; + + GPU_CHECK_CAN_SETUP(); + + GPU_SAFE_STMT( + countOK, + count <= GPU_MAX_COMMON_TEXCOORDS, + GPU_IMMEDIATE->format.texCoordCount = count); +} + + + +void gpuImmediateTexCoordSizes(const GLint *__restrict sizes) +{ + size_t i; + + GPU_CHECK_CAN_SETUP(); + + for (i = 0; i < GPU_IMMEDIATE->format.texCoordCount; i++) { + GLboolean texCoordSizeOK; + + GPU_SAFE_STMT( + texCoordSizeOK, + sizes[i] > 0 && sizes[i] <= 4, + GPU_IMMEDIATE->format.texCoordSize[i] = sizes[i]); + } +} + + + +void gpuImmediateSamplerCount(size_t count) +{ + GLboolean countOK; + + GPU_CHECK_CAN_SETUP(); + + GPU_SAFE_STMT( + countOK, + count <= GPU_MAX_COMMON_SAMPLERS, + GPU_IMMEDIATE->format.samplerCount = count); +} + + + +void gpuImmediateSamplerMap(const GLint *__restrict map) +{ + size_t i; + + GPU_CHECK_CAN_SETUP(); + + for (i = 0; i < GPU_IMMEDIATE->format.samplerCount; i++) { + GLboolean mapOK; + + GPU_SAFE_STMT( + mapOK, + map[i] >= 0 && map[i] <= GPU_IMMEDIATE->lastTexture, + GPU_IMMEDIATE->format.samplerMap[i] = map[i]); + } +} + + + +void gpuImmediateFloatAttribCount(size_t count) +{ + GLboolean countOK; + + GPU_CHECK_CAN_SETUP(); + + GPU_SAFE_STMT( + countOK, + count <= GPU_MAX_FLOAT_ATTRIBS, + GPU_IMMEDIATE->format.attribCount_f = count); +} + + + +void gpuImmediateFloatAttribSizes(const GLint *__restrict sizes) +{ + size_t i; + + GPU_CHECK_CAN_SETUP(); + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) { + GLboolean sizeOK; + + GPU_SAFE_STMT( + sizeOK, + sizes[i] > 0 && sizes[i] <= 4, + GPU_IMMEDIATE->format.attribSize_f[i] = sizes[i]); + } +} + + + +void gpuImmediateFloatAttribIndexMap(const GLuint *__restrict map) +{ + size_t i; + + GPU_CHECK_CAN_SETUP(); + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) { + GPU_IMMEDIATE->format.attribIndexMap_f[i] = map[i]; + } +} + + + +void gpuImmediateUbyteAttribCount(size_t count) +{ + GLboolean countOK; + + GPU_CHECK_CAN_SETUP(); + + GPU_SAFE_STMT( + countOK, + count <= GPU_MAX_UBYTE_ATTRIBS, + GPU_IMMEDIATE->format.attribCount_ub = count); +} + +void gpuImmediateUbyteAttribSizes(const GLint *__restrict sizes) +{ + size_t i; + + GPU_CHECK_CAN_SETUP(); + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) { + GLboolean sizeOK; + + GPU_SAFE_STMT( + sizeOK, + sizes[i] > 0 && sizes[i] <= 4, //-V112 + GPU_IMMEDIATE->format.attribSize_ub[i] = sizes[i]); + } +} + + + +void gpuImmediateUbyteAttribIndexMap(const GLuint *__restrict map) +{ + size_t i; + + GPU_CHECK_CAN_SETUP(); + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) { + GPU_IMMEDIATE->format.attribIndexMap_ub[i] = map[i]; + } +} + + + +static GLboolean end_begin(void) +{ +#if GPU_SAFETY + GPU_IMMEDIATE->hasOverflowed = GL_TRUE; +#endif + + if (!ELEM( + GPU_IMMEDIATE->mode, + GL_NOOP, + GL_LINE_LOOP, + GL_POLYGON, + GL_QUAD_STRIP, + GL_LINE_STRIP, + GL_TRIANGLE_STRIP)) // XXX jwilkins: can restart some of these, but need to put in the logic (could be problematic with mapped VBOs?) + { + gpu_end_buffer_gl(); + + GPU_IMMEDIATE->mappedBuffer = NULL; + GPU_IMMEDIATE->offset = 0; + GPU_IMMEDIATE->count = 1; /* count the vertex that triggered this */ + + gpu_begin_buffer_gl(); + + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + + + +static void gpu_copy_vertex(void) +{ + size_t i; + size_t size; + size_t offset; + GLubyte *__restrict mappedBuffer; + +#if GPU_SAFETY + { + int maxVertexCountOK; + GPU_SAFE_RETURN(GPU_IMMEDIATE->maxVertexCount != 0, maxVertexCountOK,); + } +#endif + + if (GPU_IMMEDIATE->count == GPU_IMMEDIATE->lastPrimVertex) { + GLboolean restarted; + + restarted = end_begin(); /* draw and clear buffer */ + + GPU_ASSERT(restarted); + + if (!restarted) + return; + } + else { + GPU_IMMEDIATE->count++; + } + + mappedBuffer = GPU_IMMEDIATE->mappedBuffer; + offset = GPU_IMMEDIATE->offset; + + /* vertex */ + + size = (size_t)(GPU_IMMEDIATE->format.vertexSize) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->vertex, size); + offset += size; + + /* normal */ + + if (GPU_IMMEDIATE->format.normalSize != 0) { + /* normals are always have 3 components */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->normal, 3*sizeof(GLfloat)); + offset += 3*sizeof(GLfloat); + } + + /* color */ + + if (GPU_IMMEDIATE->format.colorSize != 0) { + /* 4 bytes are always reserved for color, for efficient memory alignment */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->color, 4*sizeof(GLubyte)); + offset += 4*sizeof(GLubyte); + } + + /* texture coordinate(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.texCoordCount; i++) { + size = (size_t)(GPU_IMMEDIATE->format.texCoordSize[i]) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->texCoord[i], size); + offset += size; + } + + /* float vertex attribute(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) { + size = (size_t)(GPU_IMMEDIATE->format.attribSize_f[i]) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->attrib_f[i], size); + offset += size; + } + + /* unsigned byte vertex attribute(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) { + /* 4 bytes are always reserved for byte attributes, for efficient memory alignment */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->attrib_ub[i], 4*sizeof(GLubyte)); + offset += 4*sizeof(GLubyte); + } + + GPU_IMMEDIATE->offset = offset; +} + + + +/* vertex formats */ + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_V2(const char* file, int line) +#else +void gpuImmediateFormat_V2(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_V2\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(2, 0, 0); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_C4_V2(const char* file, int line) +#else +void gpuImmediateFormat_C4_V2(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_C4_V2\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(2, 0, 4); //-V112 + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_T2_V2(const char* file, int line) +#else +void gpuImmediateFormat_T2_V2(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_T2_V2\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + GLint texCoordSizes[1] = { 2 }; + GLint samplerMap [1] = { 0 }; + + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(2, 0, 0); + + gpuImmediateTexCoordCount(1); + gpuImmediateTexCoordSizes(texCoordSizes); + + gpuImmediateSamplerCount(1); + gpuImmediateSamplerMap(samplerMap); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_T2_V3(const char* file, int line) +#else +void gpuImmediateFormat_T2_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_T2_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + GLint texCoordSizes[1] = { 2 }; + GLint samplerMap [1] = { 0 }; + + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 0, 0); + + gpuImmediateTexCoordCount(1); + gpuImmediateTexCoordSizes(texCoordSizes); + + gpuImmediateSamplerCount(1); + gpuImmediateSamplerMap(samplerMap); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_T2_C4_V2(const char* file, int line) +#else +void gpuImmediateFormat_T2_C4_V2(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_T2_C4_V2\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + GLint texCoordSizes[1] = { 2 }; + GLint samplerMap [1] = { 0 }; + + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(2, 0, 4); //-V112 + + gpuImmediateTexCoordCount(1); + gpuImmediateTexCoordSizes(texCoordSizes); + + gpuImmediateSamplerCount(1); + gpuImmediateSamplerMap(samplerMap); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_V3(const char* file, int line) +#else +void gpuImmediateFormat_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 0, 0); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_N3_V3(const char* file, int line) +#else +void gpuImmediateFormat_N3_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_N3_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 3, 0); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_C4_V3(const char* file, int line) +#else +void gpuImmediateFormat_C4_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_C4_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 0, 4); //-V112 + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_C4_N3_V3(const char* file, int line) +#else +void gpuImmediateFormat_C4_N3_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_C4_N3_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 3, 4); //-V112 + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_T2_C4_N3_V3(const char* file, int line) +#else +void gpuImmediateFormat_T2_C4_N3_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_T2_C4_N3_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + GLint texCoordSizes[1] = { 2 }; + GLint samplerMap [1] = { 0 }; + + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 3, 4); //-V112 + + gpuImmediateTexCoordCount(1); + gpuImmediateTexCoordSizes(texCoordSizes); + + gpuImmediateSamplerCount(1); + gpuImmediateSamplerMap(samplerMap); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateFormat_T3_C4_V3(const char* file, int line) +#else +void gpuImmediateFormat_T3_C4_V3(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateFormat_T3_C4_V3\n", file, line); +#endif + + if (gpuImmediateLockCount() == 0) { + GLint texCoordSizes[1] = { 3 }; + GLint samplerMap [1] = { 0 }; + + gpuImmediateFormatReset(); + + gpuImmediateElementSizes(3, 0, 4); //-V112 + + gpuImmediateTexCoordCount(1); + gpuImmediateTexCoordSizes(texCoordSizes); + + gpuImmediateSamplerCount(1); + gpuImmediateSamplerMap(samplerMap); + } + + gpuImmediateLock(); +} + +#if GPU_SAFETY +void gpuSafetyImmediateUnformat(const char* file, int line) +#else +void gpuImmediateUnformat(void) +#endif +{ +#if GPU_SAFETY + printf("%s(%d): gpuImmediateUnformat\n", file, line); +#endif + + gpuImmediateUnlock(); +} + + + +static GPUimmediate* immediateStack = NULL; /* stack size of one */ + + + +void gpuPushImmediate(void) +{ + GPUimmediate* newImmediate; + + GPU_CHECK_CAN_PUSH(); + + newImmediate = gpuNewImmediate(); + immediateStack = GPU_IMMEDIATE; + GPU_IMMEDIATE = newImmediate; +} + +GPUimmediate* gpuPopImmediate(void) +{ + GPUimmediate* newImmediate; + + GPU_CHECK_CAN_POP(); + + newImmediate = GPU_IMMEDIATE; + GPU_IMMEDIATE = immediateStack; + immediateStack = NULL; + + return newImmediate; +} + + + +static void gpu_append_client_arrays( + const GPUarrays *__restrict arrays, + GLint first, + GLsizei count) +{ + GLsizei i; + size_t size; + size_t offset; + + GLubyte *__restrict mappedBuffer; + + char *__restrict colorPointer; + char *__restrict normalPointer; + char *__restrict vertexPointer; + +#if GPU_SAFETY + { + int newVertexCountOK; + GPU_SAFE_RETURN(GPU_IMMEDIATE->count + count <= GPU_IMMEDIATE->maxVertexCount, newVertexCountOK,); + } +#endif + + vertexPointer = (char *__restrict)(arrays->vertexPointer) + (first * arrays->vertexStride); + normalPointer = (char *__restrict)(arrays->normalPointer) + (first * arrays->normalStride); + colorPointer = (char *__restrict)(arrays->colorPointer ) + (first * arrays->colorStride ); + + mappedBuffer = GPU_IMMEDIATE->mappedBuffer; + + offset = GPU_IMMEDIATE->offset; + + for (i = 0; i < count; i++) { + size = arrays->vertexSize * sizeof(GLfloat); + memcpy(mappedBuffer + offset, vertexPointer, size); + offset += size; + vertexPointer += arrays->vertexStride; + + if (normalPointer) { + memcpy(mappedBuffer + offset, normalPointer, 3*sizeof(GLfloat)); + offset += 3*sizeof(GLfloat); + normalPointer += arrays->normalStride; + } + + if (colorPointer) { + if (arrays->colorType == GL_FLOAT) { + GLubyte color[4]; + + color[0] = (GLubyte)(colorPointer[0] * 255.0f); + color[1] = (GLubyte)(colorPointer[1] * 255.0f); + color[2] = (GLubyte)(colorPointer[2] * 255.0f); + + if (arrays->colorSize == 4) { + color[3] = (GLubyte)(colorPointer[3] * 255.0f); + } + else { + color[3] = 255;; + } + + memcpy(mappedBuffer + offset, color, 4); + } + else /* assume four GL_UNSIGNED_BYTE */ { + memcpy(mappedBuffer + offset, colorPointer, 4); + } + + offset += 4; + colorPointer += arrays->colorStride; + } + } + + GPU_IMMEDIATE->offset = offset; + GPU_IMMEDIATE->count += count; +} + + + +const GPUarrays GPU_ARRAYS_V2F = { + 0, /* GLenum colorType; */ + 0, /* GLint colorSize; */ + 0, /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + 0, /* GLenum normalType; */ + 0, /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 2, /* GLint vertexSize; */ + 2 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_C4UB_V2F = { + GL_UNSIGNED_BYTE, /* GLenum colorType; */ + 4, /* GLint colorSize; */ + 4, /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + 0, /* GLenum normalType; */ + 0, /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 2, /* GLint vertexSize; */ + 2 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_C4UB_V3F = { + GL_UNSIGNED_BYTE, /* GLenum colorType; */ + 4, /* GLint colorSize; */ + 4, /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + 0, /* GLenum normalType; */ + 0, /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 3, /* GLint vertexSize; */ + 3 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_V3F = { + 0, /* GLenum colorType; */ + 0, /* GLint colorSize; */ + 0, /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + 0, /* GLenum normalType; */ + 0, /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 3, /* GLint vertexSize; */ + 3 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_C3F_V3F = { + GL_FLOAT, /* GLenum colorType; */ + 3, /* GLint colorSize; */ + 3 * sizeof(GLfloat), /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + 0, /* GLenum normalType; */ + 0, /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 3, /* GLint vertexSize; */ + 3 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_C4F_V3F = { + GL_FLOAT, /* GLenum colorType; */ + 4, /* GLint colorSize; */ + 4 * sizeof(GLfloat), /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + 0, /* GLenum normalType; */ + 0, /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 3, /* GLint vertexSize; */ + 3 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_N3F_V3F = { + 0, /* GLenum colorType; */ + 0, /* GLint colorSize; */ + 0, /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + GL_FLOAT, /* GLenum normalType; */ + 3 * sizeof(GLfloat), /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 3, /* GLint vertexSize; */ + 3 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + +const GPUarrays GPU_ARRAYS_C3F_N3F_V3F = { + GL_FLOAT, /* GLenum colorType; */ + 3, /* GLint colorSize; */ + 3 * sizeof(GLfloat), /* GLint colorStride; */ + NULL, /* void* colorPointer; */ + + GL_FLOAT, /* GLenum normalType; */ + 3 * sizeof(GLfloat), /* GLint normalStride; */ + NULL, /* void* normalPointer; */ + + GL_FLOAT, /* GLenum vertexType; */ + 3, /* GLint vertexSize; */ + 3 * sizeof(GLfloat), /* GLint vertexStride; */ + NULL, /* void* vertexPointer; */ +}; + + + +void gpuAppendClientArrays( + const GPUarrays* arrays, + GLint first, + GLsizei count) +{ + gpu_append_client_arrays(arrays, first, count); +} + + + +void gpuDrawClientArrays( + GLenum mode, + const GPUarrays *arrays, + GLint first, + GLsizei count) +{ + gpuBegin(mode); + gpu_append_client_arrays(arrays, first, count); + gpuEnd(); +} + + + +void gpuSingleClientArrays_V2F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_V2F; + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 2*sizeof(GLfloat); + + gpuImmediateFormat_V2(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + +void gpuSingleClientArrays_V3F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_V3F; + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_V3(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + +void gpuSingleClientArrays_C3F_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_C3F_V3F; + + arrays.colorPointer = colorPointer; + arrays.colorStride = colorStride != 0 ? colorStride : 3*sizeof(GLfloat); + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_C4_V3(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + +void gpuSingleClientArrays_C4F_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_C4F_V3F; + + arrays.colorPointer = colorPointer; + arrays.colorStride = colorStride != 0 ? colorStride : 4*sizeof(GLfloat); + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_C4_V3(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + +void gpuSingleClientArrays_N3F_V3F( + GLenum mode, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_N3F_V3F; + + arrays.normalPointer = normalPointer; + arrays.normalStride = normalStride != 0 ? normalStride : 3*sizeof(GLfloat); + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_N3_V3(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + +void gpuSingleClientArrays_C3F_N3F_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_C3F_N3F_V3F; + + arrays.colorPointer = colorPointer; + arrays.colorStride = colorStride != 0 ? colorStride : 3*sizeof(GLfloat); + + arrays.normalPointer = normalPointer; + arrays.normalStride = normalStride != 0 ? normalStride : 3*sizeof(GLfloat); + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_C4_N3_V3(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + +void gpuSingleClientArrays_C4UB_V2F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_C4UB_V2F; + + arrays.colorPointer = colorPointer; + arrays.colorStride = colorStride != 0 ? colorStride : 4; + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 2*sizeof(GLfloat); + + gpuImmediateFormat_C4_V2(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + + + +void gpuSingleClientArrays_C4UB_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLint first, + GLsizei count) +{ + GPUarrays arrays = GPU_ARRAYS_C4UB_V3F; + + arrays.colorPointer = colorPointer; + arrays.colorStride = colorStride != 0 ? colorStride : 4; + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_C4_V3(); + gpuDrawClientArrays(mode, &arrays, first, count); + gpuImmediateUnformat(); +} + + + +void gpuImmediateIndexRange(GLuint indexMin, GLuint indexMax) +{ + GPU_IMMEDIATE->index->indexMin = indexMin; + GPU_IMMEDIATE->index->indexMax = indexMax; +} + + + +#define FIND_RANGE(suffix, ctype) \ + static void find_range_##suffix( \ + GLuint *__restrict arrayFirst, \ + GLuint *__restrict arrayLast, \ + GLsizei count, \ + const ctype *__restrict indexes) \ +{ \ + int i; \ + \ + GPU_ASSERT(count > 0); \ + \ + *arrayFirst = indexes[0]; \ + *arrayLast = indexes[0]; \ + \ + for (i = 1; i < count; i++) { \ + if (indexes[i] < *arrayFirst) { \ + *arrayFirst = indexes[i]; \ + } \ + else if (indexes[i] > *arrayLast) { \ + *arrayLast = indexes[i]; \ + } \ + } \ +} + +FIND_RANGE(ub, GLubyte ) +FIND_RANGE(us, GLushort) +FIND_RANGE(ui, GLuint ) + + + +void gpuImmediateIndexComputeRange(void) +{ + GLuint indexMin, indexMax; + + GPUindex* index = GPU_IMMEDIATE->index; + + switch (index->type) { + case GL_UNSIGNED_BYTE: + find_range_ub(&indexMin, &indexMax, index->count, (GLubyte* )(index->mappedBuffer)); + break; + + case GL_UNSIGNED_SHORT: + find_range_us(&indexMin, &indexMax, index->count, (GLushort*)(index->mappedBuffer)); + break; + + case GL_UNSIGNED_INT: + find_range_ui(&indexMin, &indexMax, index->count, (GLuint* )(index->mappedBuffer)); + break; + + default: + GPU_ABORT(); + return; + } + + gpuImmediateIndexRange(indexMin, indexMax); +} + + + +void gpuSingleClientElements_V3F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLsizei count, + const GLuint *__restrict indexes) +{ + GLuint indexMin, indexMax; + + find_range_ui(&indexMin, &indexMax, count, indexes); + + gpuSingleClientRangeElements_V3F( + mode, + vertexPointer, + vertexStride, + indexMin, + indexMax, + count, + indexes); +} + +void gpuSingleClientElements_N3F_V3F( + GLenum mode, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLsizei count, + const GLuint *__restrict indexes) +{ + GLuint indexMin, indexMax; + + find_range_ui(&indexMin, &indexMax, count, indexes); + + gpuSingleClientRangeElements_N3F_V3F( + mode, + normalPointer, + normalStride, + vertexPointer, + vertexStride, + indexMin, + indexMax, + count, + indexes); +} + +void gpuSingleClientElements_C4UB_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLsizei count, + const GLuint *__restrict indexes) +{ + GLuint indexMin, indexMax; + + find_range_ui(&indexMin, &indexMax, count, indexes); + + gpuSingleClientRangeElements_C4UB_V3F( + mode, + colorPointer, + colorStride, + vertexPointer, + vertexStride, + indexMin, + indexMax, + count, + indexes); +} + + + +void gpuDrawClientRangeElements( + GLenum mode, + const GPUarrays *__restrict arrays, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes) +{ + GLuint indexRange = indexMax - indexMin + 1; + + gpuBegin(GL_NOOP); + gpuAppendClientArrays(arrays, indexMin, indexRange); + gpuEnd(); + + gpuIndexBegin(GL_UNSIGNED_INT); + gpuIndexRelativeuiv(indexRange + indexMin, count, indexes); + gpuIndexEnd(); + + gpuImmediateIndexRange(indexMin, indexMax); + + GPU_IMMEDIATE->mode = mode; + gpu_draw_range_elements_gl(); +} + +void gpuSingleClientRangeElements_V3F( + GLenum mode, + const void *__restrict vertexPointer, + GLint vertexStride, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes) +{ + GPUarrays arrays = GPU_ARRAYS_V3F; + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_V3(); + gpuDrawClientRangeElements(mode, &arrays, indexMin, indexMax, count, indexes); + gpuImmediateUnformat(); +} + +void gpuSingleClientRangeElements_N3F_V3F( + GLenum mode, + const void *__restrict normalPointer, + GLint normalStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes) +{ + GPUarrays arrays = GPU_ARRAYS_N3F_V3F; + + arrays.normalPointer = normalPointer; + arrays.normalStride = normalStride != 0 ? normalStride : 3*sizeof(GLfloat); + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_N3_V3(); + gpuDrawClientRangeElements(mode, &arrays, indexMin, indexMax, count, indexes); + gpuImmediateUnformat(); +} + +void gpuSingleClientRangeElements_C4UB_V3F( + GLenum mode, + const void *__restrict colorPointer, + GLint colorStride, + const void *__restrict vertexPointer, + GLint vertexStride, + GLuint indexMin, + GLuint indexMax, + GLsizei count, + const GLuint *__restrict indexes) +{ + GPUarrays arrays = GPU_ARRAYS_C4UB_V3F; + + arrays.normalPointer = colorPointer; + arrays.normalStride = colorStride != 0 ? colorStride : 4*sizeof(GLubyte); + + arrays.vertexPointer = vertexPointer; + arrays.vertexStride = vertexStride != 0 ? vertexStride : 3*sizeof(GLfloat); + + gpuImmediateFormat_C4_V3(); + gpuDrawClientRangeElements(mode, &arrays, indexMin, indexMax, count, indexes); + gpuImmediateUnformat(); +} + + + +GPUindex* gpuNewIndex(void) +{ + return (GPUindex*)MEM_callocN(sizeof(GPUindex), "GPUindex"); +} + + + +void gpuDeleteIndex(GPUindex *__restrict index) +{ + if (index) { + GPUimmediate* immediate = index->immediate; + + gpu_index_shutdown_buffer_gl(index); + immediate->index = NULL; + + MEM_freeN(index); + } +} + + + +void gpuImmediateIndex(GPUindex * index) +{ + //GPU_ASSERT(GPU_IMMEDIATE->index == NULL); + + if (index) + index->immediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE->index = index; +} + + + +GPUindex* gpuGetImmediateIndex() +{ + return GPU_IMMEDIATE->index; +} + + + +void gpuImmediateMaxIndexCount(GLsizei maxIndexCount, GLenum type) +{ + GPU_ASSERT(GPU_IMMEDIATE); + GPU_ASSERT(GPU_IMMEDIATE->index); + + GPU_IMMEDIATE->index->maxIndexCount = maxIndexCount; + GPU_IMMEDIATE->index->type = type; +} + + + +void gpuIndexBegin(GLenum type) +{ + GPUindex* index; + + GPU_ASSERT(ELEM3(type, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT)); + + index = GPU_IMMEDIATE->index; + + index->count = 0; + index->indexMin = 0; + index->indexMax = 0; + index->type = type; + + gpu_index_begin_buffer_gl(); +} + + + +#define INDEX_RELATIVE(suffix, ctype, glsymbol) \ +void gpuIndexRelative##suffix(GLint offset, GLsizei count, const ctype *__restrict indexes) \ +{ \ + int i; \ + int start; \ + int indexStart; \ + GPUindex* index; \ + \ + GPU_ASSERT(GPU_IMMEDIATE); \ + GPU_ASSERT(GPU_IMMEDIATE->index); \ + GPU_ASSERT(GPU_IMMEDIATE->index->type == glsymbol); \ + \ + { \ + GLboolean indexCountOK; \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->index->count + count <= GPU_IMMEDIATE->index->maxIndexCount, indexCountOK,); \ + } \ + \ + start = GPU_IMMEDIATE->count; \ + index = GPU_IMMEDIATE->index; \ + indexStart = index->count; \ + \ + for (i = 0; i < count; i++) { \ + ((ctype*)(index->mappedBuffer))[indexStart+i] = start - offset + ((ctype*)indexes)[i]; \ + } \ + \ + index->count += count; \ + index->offset = count*sizeof(ctype); \ +} + +INDEX_RELATIVE(ubv, GLubyte, GL_UNSIGNED_BYTE ) +INDEX_RELATIVE(usv, GLushort, GL_UNSIGNED_SHORT) +INDEX_RELATIVE(uiv, GLuint, GL_UNSIGNED_INT ) + + + +#define INDEX(suffix, ctype, glsymbol) \ +void gpuIndex##suffix(ctype nextIndex) \ +{ \ + GPUindex* index; \ + \ + GPU_ASSERT(GPU_IMMEDIATE); \ + GPU_ASSERT(GPU_IMMEDIATE->index); \ + GPU_ASSERT(GPU_IMMEDIATE->index->type == glsymbol); \ + \ + { \ + GLboolean indexCountOK; \ + GPU_SAFE_RETURN(GPU_IMMEDIATE->index->count < GPU_IMMEDIATE->index->maxIndexCount, indexCountOK,); \ + } \ + \ + index = GPU_IMMEDIATE->index; \ + ((ctype*)(index->mappedBuffer))[index->count] = nextIndex; \ + index->count++; \ + index->offset += sizeof(ctype); \ +} + +INDEX(ub, GLubyte, GL_UNSIGNED_BYTE ) +INDEX(us, GLushort, GL_UNSIGNED_SHORT) +INDEX(ui, GLuint, GL_UNSIGNED_INT ) + + + +void gpuIndexEnd(void) +{ + gpu_index_end_buffer_gl(); + + GPU_IMMEDIATE->index->mappedBuffer = NULL; +} diff --git a/source/blender/gpu/intern/gpu_immediate_gl.c b/source/blender/gpu/intern/gpu_immediate_gl.c new file mode 100644 index 00000000000..9ff22786566 --- /dev/null +++ b/source/blender/gpu/intern/gpu_immediate_gl.c @@ -0,0 +1,729 @@ +/* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* The Original Code is Copyright (C) 2012 Blender Foundation. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): Alexandr Kuznetsov, Jason Wilkins. +* +* ***** END GPL LICENSE BLOCK ***** +*/ + +/** \file blender/gpu/intern/gpu_immediate_gl.c +* \ingroup gpu +*/ + +/* my interface */ +#include "intern/gpu_immediate_intern.h" + +/* internal */ +#include "intern/gpu_extensions_intern.h" +#include "intern/gpu_common_intern.h" + +#include "GPU_aspect.h" +#include "GPU_matrix.h" + +/* external */ +#include "MEM_guardedalloc.h" + +/* standard */ +#include <stddef.h> + + + +#define ALIGN64(p) (((p) + 63) & ~63) + + + +typedef struct bufferDataGLSL { + size_t size; + GLuint vao; + GLuint vbo; + GLintptr unalignedPtr; + GLubyte* mappedBuffer; + GLubyte* unmappedBuffer; +} bufferDataGLSL; + + + +static GLsizei calc_stride(void) +{ + size_t stride = 0; + GPUimmediateformat* format = &(GPU_IMMEDIATE->format); + size_t i; + + /* vertex */ + if (format->vertexSize != 0) + stride += (size_t)(format->vertexSize) * sizeof(GLfloat); + + /* normal */ + if (format->normalSize != 0) + stride += 3 * sizeof(GLfloat); /* normals always have 3 components */ + + /* color */ + if (format->colorSize != 0) + stride += 4 * sizeof(GLubyte); /* color always get 4 bytes for efficient memory alignment */ + + /* texture coordinate */ + for (i = 0; i < format->texCoordCount; i++) + stride += (size_t)(format->texCoordSize[i]) * sizeof(GLfloat); + + /* float vertex attribute */ + for (i = 0; i < format->attribCount_f; i++) + stride += (size_t)(format->attribSize_f[i]) * sizeof(GLfloat); + + /* byte vertex attribute */ + for (i = 0; i < format->attribCount_ub; i++) + stride += 4 * sizeof(GLubyte); /* byte attributes always get 4 bytes for efficient memory alignment */ + + return (GLsizei)stride; +} + + + +static void allocate(void) +{ + size_t newSize; + + GPU_CHECK_NO_ERROR(); + + GPU_IMMEDIATE->stride = calc_stride(); + + newSize = (size_t)(GPU_IMMEDIATE->stride * GPU_IMMEDIATE->maxVertexCount); + + if (GPU_IMMEDIATE->bufferData) { + bufferDataGLSL* bufferData = (bufferDataGLSL*)GPU_IMMEDIATE->bufferData; + + if (bufferData->vbo != 0) + gpu_glBindBuffer(GL_ARRAY_BUFFER, bufferData->vbo); + + if (newSize > bufferData->size) { + if (bufferData->vbo != 0) + gpu_glBufferData(GL_ARRAY_BUFFER, newSize, NULL, GL_STREAM_DRAW); + + if (bufferData->unalignedPtr != 0) { + bufferData->unalignedPtr = (GLintptr)MEM_reallocN((GLubyte*)(bufferData->unalignedPtr), newSize+63); + bufferData->unmappedBuffer = (GLubyte*)ALIGN64(bufferData->unalignedPtr); + } + + bufferData->size = newSize; + } + } + else { + bufferDataGLSL* bufferData = (bufferDataGLSL*)MEM_callocN(sizeof(bufferDataGLSL), "bufferDataGLSL"); + + if (gpu_glGenBuffers) { + gpu_glGenBuffers(1, &(bufferData->vbo)); + GPU_ASSERT(bufferData->vbo != 0); + gpu_glBindBuffer(GL_ARRAY_BUFFER, bufferData->vbo); + gpu_glBufferData(GL_ARRAY_BUFFER, newSize, NULL, GL_STREAM_DRAW); + } + + if (gpu_glMapBuffer) { + bufferData->unalignedPtr = 0; + bufferData->unmappedBuffer = NULL; + } + else { + bufferData->unalignedPtr = (GLintptr)MEM_mallocN(newSize+63, "bufferDataGLSL->unalignedPtr"); + bufferData->unmappedBuffer = (void*)ALIGN64(bufferData->unalignedPtr); + } + + bufferData->size = newSize; + + GPU_IMMEDIATE->bufferData = bufferData; + } + + GPU_CHECK_NO_ERROR(); +} + + + +static void setup(void) +{ + GPUimmediateformat* format = &(GPU_IMMEDIATE->format); + const GLsizei stride = GPU_IMMEDIATE->stride; + bufferDataGLSL* bufferData = (bufferDataGLSL*)(GPU_IMMEDIATE->bufferData); + const GLubyte* base = bufferData->vbo != 0 ? NULL : (GLubyte*)(bufferData->unmappedBuffer); + + size_t offset = 0; + + size_t i; + + /* vertex */ + GPU_common_enable_vertex_array(); + GPU_common_vertex_pointer(format->vertexSize, GL_FLOAT, stride, base + offset); + offset += (size_t)(format->vertexSize) * sizeof(GLfloat); + + /* normal */ + if (format->normalSize != 0) { + GPU_common_enable_normal_array(); + GPU_common_normal_pointer(GL_FLOAT, stride, GL_FALSE, base + offset); + offset += 3 * sizeof(GLfloat); + } + + /* color */ + if (format->colorSize != 0) { + GPU_common_enable_color_array(); + GPU_common_color_pointer(format->colorSize, GL_UNSIGNED_BYTE, stride, base + offset); + offset += 4 * sizeof(GLubyte); /* 4 bytes are always reserved for color, for efficient memory alignment */ + } + + /* texture coordinate */ + + for (i = 0; i < format->texCoordCount; i++) { + GPU_set_common_active_texture(i); + GPU_common_enable_texcoord_array(); + GPU_common_texcoord_pointer(format->texCoordSize[i], GL_FLOAT, stride, base + offset); + offset += (size_t)(format->texCoordSize[i]) * sizeof(GLfloat); + } + + GPU_set_common_active_texture(0); + + /* float vertex attribute */ + for (i = 0; i < format->attribCount_f; i++) { + if (format->attribSize_f[i] > 0) { + gpu_glVertexAttribPointer( + format->attribIndexMap_f[i], + format->attribSize_f[i], + GL_FLOAT, + format->attribNormalized_f[i], + stride, + base + offset); + + offset += (size_t)(format->attribSize_f[i]) * sizeof(GLfloat); + + gpu_glEnableVertexAttribArray(format->attribIndexMap_f[i]); + } + } + + /* byte vertex attribute */ + for (i = 0; i < format->attribCount_ub; i++) { + if (format->attribSize_ub[i] > 0) { + gpu_glVertexAttribPointer( + format->attribIndexMap_ub[i], + format->attribSize_ub[i], + GL_UNSIGNED_BYTE, + format->attribNormalized_ub[i], + stride, + base + offset); + + offset += 4 * sizeof(GLubyte); + + gpu_glEnableVertexAttribArray(format->attribIndexMap_ub[i]); + } + } +} + + + +static void unsetup(void) +{ + size_t i; + + /* vertex */ + GPU_common_disable_vertex_array(); + + /* normal */ +// if (GPU_IMMEDIATE->format.normalSize != 0) + GPU_common_disable_normal_array(); + + /* color */ +// if (GPU_IMMEDIATE->format.colorSize != 0) + GPU_common_disable_color_array(); + + /* texture coordinate */ + + for (i = 0; i < GPU_IMMEDIATE->format.texCoordCount; i++) { + GPU_set_common_active_texture(i); + +// if (GPU_IMMEDIATE->format.texCoordSize[i] != 0) + GPU_common_disable_texcoord_array(); + } + + GPU_set_common_active_texture(0); + + /* float vertex attribute */ + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) +// if (GPU_IMMEDIATE->format.attribSize_f[i] > 0) + gpu_glDisableVertexAttribArray(GPU_IMMEDIATE->format.attribIndexMap_f[i]); + + /* byte vertex attribute */ + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) +// if (GPU_IMMEDIATE->format.attribSize_ub[i] > 0) + gpu_glDisableVertexAttribArray(GPU_IMMEDIATE->format.attribIndexMap_ub[i]); +} + + + +typedef struct indexBufferDataGLSL { + GLuint vbo; + GLintptr unalignedPtr; + GLubyte* unmappedBuffer; + GLubyte* mappedBuffer; + size_t size; +} indexBufferDataGLSL; + +static void allocateIndex(void) +{ + if (GPU_IMMEDIATE->index) { + GPUindex* index; + size_t newSize; + + GPU_CHECK_NO_ERROR(); + + index = GPU_IMMEDIATE->index; + + switch(index->type) { + case GL_UNSIGNED_BYTE: + newSize = index->maxIndexCount * sizeof(GLubyte); + break; + case GL_UNSIGNED_SHORT: + newSize = index->maxIndexCount * sizeof(GLushort); + break; + case GL_UNSIGNED_INT: + newSize = index->maxIndexCount * sizeof(GLuint); + break; + default: + GPU_ABORT(); + return; + } + + if (index->bufferData) { + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)(index->bufferData); + + if (bufferData->vbo != 0) + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferData->vbo); + + if (newSize > bufferData->size) { + if (bufferData->vbo) + gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, newSize, NULL, GL_STREAM_DRAW); + + if (bufferData->unalignedPtr != 0) { + bufferData->unalignedPtr = (GLintptr)MEM_reallocN((GLubyte*)(bufferData->unalignedPtr), newSize+63); + bufferData->unmappedBuffer = (GLubyte*)ALIGN64(bufferData->unalignedPtr); + } + + bufferData->size = newSize; + } + } + else { + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)MEM_callocN(sizeof(indexBufferDataGLSL), "indexBufferDataGLSL"); + + if (gpu_glGenBuffers) { + gpu_glGenBuffers(1, &(bufferData->vbo)); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferData->vbo); + gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, newSize, NULL, GL_STREAM_DRAW); + } + + if (gpu_glMapBuffer) { + bufferData->unalignedPtr = 0; + bufferData->unmappedBuffer = NULL; + } + else { + bufferData->unalignedPtr = (GLintptr)MEM_mallocN(newSize+63, "indexBufferDataGLSL->unalignedPtr"); + bufferData->unmappedBuffer = (GLubyte*)ALIGN64(bufferData->unalignedPtr); + } + + bufferData->size = newSize; + + index->bufferData = bufferData; + } + + GPU_CHECK_NO_ERROR(); + } +} + + + +static void static_element_array(GLuint* idOut, GLsizeiptr size, const GLvoid* indexes) +{ + gpu_glGenBuffers(1, idOut); + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *idOut); + gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indexes, GL_STATIC_DRAW); +} + + + +/* quad emulation*/ + +#if GPU_SAFETY +static bool quad_init = false; +#endif + +static const GLsizeiptr VQEOS_SIZE = sizeof(GLushort) * 3 * 65536 / 2; +static const GLsizeiptr VQEOC_SIZE = sizeof(GLubyte) * 3 * 256 / 2; + +static GLushort* vqeos; +static GLubyte* vqeoc; + +static GLuint vqeos_buf; +static GLuint vqeoc_buf; + + + +static void quad_free_heap(void) +{ + if (vqeoc) { + MEM_freeN(vqeoc); + vqeoc = NULL; + } + + if (vqeos) { + MEM_freeN(vqeos); + vqeos = NULL; + } +} + + + +static void quad_elements_init(void) +{ + + int i, j; + + GPU_ASSERT(!quad_init); + + vqeos = (GLushort*)MEM_mallocN(VQEOS_SIZE, "vqeos"); + + j = 0; + for (i = 0; i < 65535; i++) { + vqeos[j++] = (GLushort)i; + + if (i % 4 == 3) { + vqeos[j++] = i-3; + vqeos[j++] = i-1; + } + } + + vqeoc = (GLubyte* )MEM_mallocN(VQEOC_SIZE, "vqeoc"); + + for (i = 0; i < 255; i++) + vqeoc[i] = (GLubyte)(vqeos[i]); + + if (gpu_glGenBuffers) { + static_element_array(&vqeoc_buf, VQEOC_SIZE, vqeoc); + static_element_array(&vqeos_buf, VQEOS_SIZE, vqeos); + + quad_free_heap(); + } + +#if GPU_SAFETY + quad_init = true; +#endif +} + + + +static void quad_elements_exit(void) +{ + quad_free_heap(); + + if (vqeoc_buf != 0) { + gpu_glDeleteBuffers(1, &vqeoc_buf); + vqeoc_buf = 0; + } + + if (vqeos_buf != 0) { + gpu_glDeleteBuffers(1, &vqeos_buf); + vqeos_buf = 0; + } + +#if GPU_SAFETY + quad_init = false; +#endif +} + + +void gpu_immediate_init(void) +{ + quad_elements_init(); +} + + + +void gpu_immediate_exit(void) +{ + quad_elements_exit(); +} + + + +void gpu_lock_buffer_gl(void) +{ + allocate(); + allocateIndex(); + + if (gpu_glGenVertexArrays != NULL) { + bufferDataGLSL* bufferData = (bufferDataGLSL*)(GPU_IMMEDIATE->bufferData); + bool init = (bufferData->vao == 0); + + if (init) + gpu_glGenVertexArrays(1, &(bufferData->vao)); + + gpu_glBindVertexArray(bufferData->vao); + + if (init) + setup(); + } + else { + setup(); + } +} + + + +void gpu_begin_buffer_gl(void) +{ + bufferDataGLSL* bufferData = (bufferDataGLSL*)(GPU_IMMEDIATE->bufferData); + + bufferData->mappedBuffer = + (GLubyte*)gpu_buffer_start_update(GL_ARRAY_BUFFER, bufferData->unmappedBuffer); + + GPU_IMMEDIATE->mappedBuffer = bufferData->mappedBuffer; +} + + + +void gpu_end_buffer_gl(void) +{ + bufferDataGLSL* bufferData = (bufferDataGLSL*)(GPU_IMMEDIATE->bufferData); + + GPU_CHECK_NO_ERROR(); + + if (bufferData->mappedBuffer != NULL) { + gpu_buffer_finish_update(GL_ARRAY_BUFFER, GPU_IMMEDIATE->offset, bufferData->mappedBuffer); + + bufferData ->mappedBuffer = NULL; + GPU_IMMEDIATE->mappedBuffer = NULL; + } + + if (!(GPU_IMMEDIATE->mode == GL_NOOP || GPU_IMMEDIATE->count == 0)) { + if (!GPU_commit_aspect()) + return; + + unsetup(); + setup(); + gpu_commit_current (); + gpu_commit_samplers(); + + if (GPU_IMMEDIATE->mode != GL_QUADS) { + glDrawArrays(GPU_IMMEDIATE->mode, 0, GPU_IMMEDIATE->count); + GPU_CHECK_NO_ERROR(); + } + else { + if (GPU_IMMEDIATE->count <= 255){ + if (vqeoc_buf != 0) + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vqeoc_buf); + + glDrawElements(GL_TRIANGLES, 3 * GPU_IMMEDIATE->count / 2, GL_UNSIGNED_BYTE, vqeoc); + GPU_CHECK_NO_ERROR(); + } + else if(GPU_IMMEDIATE->count <= 65535) { + if (vqeos_buf != 0) + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vqeos_buf); + + glDrawElements(GL_TRIANGLES, 3 * GPU_IMMEDIATE->count / 2, GL_UNSIGNED_SHORT, vqeos); + GPU_CHECK_NO_ERROR(); + } + else { + printf("To big GL_QUAD object to draw. Vertices: %i", GPU_IMMEDIATE->count); + } + + if (vqeoc_buf != 0 || vqeos_buf != 0) + gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ((indexBufferDataGLSL*)(GPU_IMMEDIATE->index->bufferData))->vbo); + + GPU_CHECK_NO_ERROR(); + } + + unsetup(); + GPU_CHECK_NO_ERROR(); + } +} + + + +void gpu_unlock_buffer_gl(void) +{ + bufferDataGLSL* bufferData = (bufferDataGLSL*)(GPU_IMMEDIATE->bufferData); + + if (bufferData->vao != 0) + gpu_glBindVertexArray(0); + else + unsetup(); +} + + + +void gpu_index_shutdown_buffer_gl(GPUindex *__restrict index) +{ + if (index && index->bufferData) { + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)(index->bufferData); + + if (bufferData->vbo != 0) + gpu_glDeleteBuffers(1, &(bufferData->vbo)); + + if (bufferData->unalignedPtr != 0) + MEM_freeN((GLubyte*)(bufferData->unalignedPtr)); + + MEM_freeN(index->bufferData); + } +} + + + +void gpu_shutdown_buffer_gl(GPUimmediate *__restrict immediate) +{ + if (immediate->bufferData) { + bufferDataGLSL* bufferData = (bufferDataGLSL*)(immediate->bufferData); + + if (bufferData->unalignedPtr != 0) { + MEM_freeN((GLubyte*)(bufferData->unalignedPtr)); + } + + if (bufferData->vao != 0) + gpu_glDeleteVertexArrays(1, &(bufferData->vao)); + + if (bufferData->vbo != 0) + gpu_glDeleteBuffers(1, &(bufferData->vbo)); + + MEM_freeN(immediate->bufferData); + immediate->bufferData = NULL; + + gpu_index_shutdown_buffer_gl(immediate->index); + } +} + + + +void gpu_index_begin_buffer_gl(void) +{ + GPUindex *__restrict index = GPU_IMMEDIATE->index; + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)(index->bufferData); + + bufferData->mappedBuffer = + (GLubyte*)gpu_buffer_start_update(GL_ELEMENT_ARRAY_BUFFER, bufferData->unmappedBuffer); + + index->mappedBuffer = bufferData->mappedBuffer; +} + + + +void gpu_index_end_buffer_gl(void) +{ + GPUindex *__restrict index = GPU_IMMEDIATE->index; + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)(index->bufferData); + + gpu_buffer_finish_update(GL_ELEMENT_ARRAY_BUFFER, index->offset, bufferData->mappedBuffer); + + bufferData->mappedBuffer = NULL; + index ->mappedBuffer = NULL; +} + + + +void gpu_draw_elements_gl(void) +{ + GPUindex* index = GPU_IMMEDIATE->index; + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)(index->bufferData); + + GPU_CHECK_NO_ERROR(); + + if (!GPU_commit_aspect()) + return; + + unsetup(); + setup(); + gpu_commit_current (); + gpu_commit_samplers(); + + glDrawElements( + GPU_IMMEDIATE->mode, + index->count, + index->type, + bufferData->vbo != 0 ? NULL : bufferData->unmappedBuffer); + + unsetup(); + + GPU_CHECK_NO_ERROR(); +} + +void gpu_draw_range_elements_gl(void) +{ + GPUindex* index = GPU_IMMEDIATE->index; + indexBufferDataGLSL* bufferData = (indexBufferDataGLSL*)(index->bufferData); + + GPU_CHECK_NO_ERROR(); + + if (!GPU_commit_aspect()) + return; + + unsetup(); + setup(); + gpu_commit_current (); + gpu_commit_samplers(); + +#if defined(WITH_GL_PROFILE_CORE) || defined(WITH_GL_PROFILE_COMPAT) + glDrawRangeElements( + GPU_IMMEDIATE->mode, + index->indexMin, + index->indexMax, + index->count, + index->type, + bufferData->vbo != 0 ? NULL : bufferData->unmappedBuffer); +#else + glDrawElements( + GPU_IMMEDIATE->mode, + index->count, + index->type, + bufferData->vbo != 0 ? NULL : bufferData->unmappedBuffer); +#endif + + unsetup(); + + GPU_CHECK_NO_ERROR(); +} + + + +void gpu_commit_current(void) +{ + if (GPU_IMMEDIATE->format.colorSize == 0) + GPU_common_color_4ubv(GPU_IMMEDIATE->color); + + if (GPU_IMMEDIATE->format.normalSize == 0) + GPU_common_normal_3fv(GPU_IMMEDIATE->normal); +} + + + +void gpu_commit_samplers(void) +{ + const struct GPUcommon* common = gpu_get_common(); + + if (common) { + GPU_CHECK_NO_ERROR(); + + gpu_glUniform1iv( + common->sampler[0], + GPU_IMMEDIATE->format.samplerCount, + GPU_IMMEDIATE->format.samplerMap); + + GPU_CHECK_NO_ERROR(); + } +} diff --git a/source/blender/gpu/intern/gpu_immediate_intern.h b/source/blender/gpu/intern/gpu_immediate_intern.h new file mode 100644 index 00000000000..9954d8a1bd9 --- /dev/null +++ b/source/blender/gpu/intern/gpu_immediate_intern.h @@ -0,0 +1,48 @@ +#ifndef _GPU_IMMEDIATE_INTERN_H_ +#define _GPU_IMMEDIATE_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov, Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_immediate_intern.h + * \ingroup gpu + */ + +#include "GPU_immediate.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_immediate_init(void); +void gpu_immediate_exit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_IMMEDIATE_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c new file mode 100644 index 00000000000..6f9ed227653 --- /dev/null +++ b/source/blender/gpu/intern/gpu_init_exit.c @@ -0,0 +1,146 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_init_exit.c + * \ingroup gpu + */ + +/* my interface */ +#include "GPU_init_exit.h" + +/* my library */ +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_aspect_intern.h" +#include "intern/gpu_basic_intern.h" +#include "intern/gpu_blender_aspect_intern.h" +#include "intern/gpu_clipping_intern.h" +#include "intern/gpu_codegen.h" +#include "intern/gpu_common_intern.h" +#include "intern/gpu_extensions_intern.h" +#include "intern/gpu_font_intern.h" +#include "intern/gpu_immediate_intern.h" +#include "intern/gpu_lighting_intern.h" +#include "intern/gpu_matrix_intern.h" +#include "intern/gpu_pixels_intern.h" +#include "intern/gpu_raster_intern.h" +#include "intern/gpu_select_intern.h" +#include "intern/gpu_sprite_intern.h" +#include "intern/gpu_state_latch_intern.h" + +/* + +although the order of initialization and shutdown should not matter +(except for the extensions), I chose alphabetical and reverse alphabetical order + +*/ + +static GPUimmediate* gpu_immediate; +static GPUindex* gpu_index; + +static bool initialized = false; + +void GPU_init(void) +{ + /* can't avoid calling this multiple times, see wm_window_add_ghostwindow */ + if (initialized) + return; + + initialized = true; + + gpu_extensions_init(); /* must come first */ + +#if 0 + gpu_aspect_init(); + gpu_basic_init(); + gpu_blender_aspect_init(); + gpu_clipping_init(); +#endif + gpu_codegen_init(); +#if 0 + gpu_common_init(); + gpu_font_init(); + gpu_immediate_init(); + gpu_lighting_init(); + gpu_matrix_init(); + gpu_pixels_init(); + gpu_raster_init(); + gpu_select_init(); + gpu_sprite_init(); + gpu_state_latch_init(); + + gpu_immediate = gpuNewImmediate(); + gpuImmediateMakeCurrent(gpu_immediate); + gpuImmediateMaxVertexCount(500000); // XXX jwilkins: temporary! + + gpu_index = gpuNewIndex(); + gpuImmediateIndex(gpu_index); + gpuImmediateMaxIndexCount(50000, GL_UNSIGNED_SHORT); // XXX jwilkins: temporary! + + GPU_aspect_begin(GPU_ASPECT_BASIC, NULL); +#endif +} + + + +void GPU_exit(void) +{ + GPU_ASSERT(initialized); + +#if 0 + GPU_aspect_end(); + + gpuDeleteIndex(gpu_index); + gpuImmediateIndex(NULL); + + gpuImmediateMakeCurrent(NULL); + gpuDeleteImmediate(gpu_immediate); + + gpu_state_latch_exit(); + gpu_sprite_exit(); + gpu_select_exit(); + gpu_raster_exit(); + gpu_pixels_exit(); + gpu_matrix_exit(); + gpu_lighting_exit(); + gpu_immediate_exit(); + gpu_font_exit(); + gpu_common_exit(); +#endif + gpu_codegen_exit(); +#if 0 + gpu_clipping_exit(); + gpu_blender_aspect_exit(); + gpu_basic_exit(); + gpu_aspect_exit(); +#endif + + gpu_extensions_exit(); /* must come last */ + + initialized = false; +} diff --git a/source/blender/gpu/intern/gpu_lighting.c b/source/blender/gpu/intern/gpu_lighting.c new file mode 100644 index 00000000000..85aa8d003ed --- /dev/null +++ b/source/blender/gpu/intern/gpu_lighting.c @@ -0,0 +1,252 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_lighting.c + * \ingroup gpu + */ + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + +/* my interface */ +#include "intern/gpu_lighting_intern.h" + +/* my library */ +#include "GPU_extensions.h" +#include "GPU_matrix.h" +#include "GPU_safety.h" +#include "GPU_common.h" + +/* internal */ +#include "intern/gpu_common_intern.h" + +/* external */ +#include "BLI_math_vector.h" + + + +typedef struct GPUbasicmaterial { + float specular[4]; + int shininess; +} GPUbasicmaterial; + +static struct LIGHTING { + GPUbasiclight light[GPU_MAX_COMMON_LIGHTS]; + GPUbasicmaterial material; + + uint32_t light_count; +} LIGHTING; + + + + +const GPUbasiclight GPU_DEFAULT_LIGHT = +{ + { 0, 0, 1, 0 }, /* position: directional light that is straight above (in eye coordinates) */ + { 1, 1, 1, 1 }, /* diffuse : white */ + { 1, 1, 1, 1 }, /* specular: white */ + 1, 0, 0, /* attenuation polynomal coefficients: no attenuation */ + { 0, 0, 1 }, /* spotlight direction: straight ahead (in eye coordinates) */ + 180, 0 /* spotlight parameters: no spotlight */ +}; + + + +void gpu_lighting_init(void) +{ + GPU_restore_basic_lights(1, &GPU_DEFAULT_LIGHT); +} + + + +void gpu_lighting_exit(void) +{ +} + + + +bool gpu_lighting_is_fast(void) +{ + int i; + + for (i = 0; i < LIGHTING.light_count; i++) + if (LIGHTING.light[i].position[3] != 0) + return false; + + return true; +} + + + +void gpu_commit_lighting(void) +{ + const struct GPUcommon* common = gpu_get_common(); + const struct GPUbasiclight* light = LIGHTING.light; + + int i; + + for (i = 0; i < LIGHTING.light_count; i++) { + if (common) { + glUniform4fv(common->light_position [i], 1, light->position); + glUniform4fv(common->light_diffuse [i], 1, light->diffuse); + glUniform4fv(common->light_specular [i], 1, light->specular); + + glUniform1f (common->light_constant_attenuation [i], light->constant_attenuation); + glUniform1f (common->light_linear_attenuation [i], light->linear_attenuation); + glUniform1f (common->light_quadratic_attenuation[i], light->quadratic_attenuation); + + glUniform3fv(common->light_spot_direction [i], 1, light->spot_direction); + glUniform1f (common->light_spot_cutoff [i], light->spot_cutoff); + glUniform1f (common->light_spot_cos_cutoff [i], DEG2RAD(light->spot_cutoff)); + glUniform1f (common->light_spot_exponent [i], light->spot_exponent); + } + +#if defined(WITH_GL_PROFILE_COMPAT) + if (i < 8) { + glEnable (GL_LIGHT0+i); + + glLightfv(GL_LIGHT0+i, GL_POSITION, light->position); // deprecated + glLightfv(GL_LIGHT0+i, GL_DIFFUSE, light->diffuse); // deprecated + glLightfv(GL_LIGHT0+i, GL_SPECULAR, light->specular); // deprecated + + glLightf (GL_LIGHT0+i, GL_CONSTANT_ATTENUATION, light->constant_attenuation); // deprecated + glLightf (GL_LIGHT0+i, GL_LINEAR_ATTENUATION, light->linear_attenuation); // deprecated + glLightf (GL_LIGHT0+i, GL_QUADRATIC_ATTENUATION, light->quadratic_attenuation); // deprecated + + glLightfv(GL_LIGHT0+i, GL_SPOT_DIRECTION, light->spot_direction); // deprecated + glLightf (GL_LIGHT0+i, GL_SPOT_CUTOFF, light->spot_cutoff); // deprecated + glLightf (GL_LIGHT0+i, GL_SPOT_EXPONENT, light->spot_exponent); // deprecated + } +#endif + + light++; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + for (; i < 8; i++) { + glDisable(GL_LIGHT0+i); // deprecated + } +#endif + + if (common) + glUniform1i(common->light_count, LIGHTING.light_count); +} + + + +void gpu_commit_material(void) +{ + const struct GPUcommon* common = gpu_get_common(); + const struct GPUbasicmaterial* material = &(LIGHTING.material); + +GPU_CHECK_NO_ERROR(); + if (common) { + glUniform4fv(common->material_specular, 1, material->specular); +GPU_CHECK_NO_ERROR(); + glUniform1f (common->material_shininess, (float)(material->shininess)); +GPU_CHECK_NO_ERROR(); + } + +#if defined(WITH_GL_PROFILE_COMPAT) + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material->specular); // deprecated + glMateriali (GL_FRONT_AND_BACK, GL_SHININESS, material->shininess); // deprecated +#endif +GPU_CHECK_NO_ERROR(); +} + + + +/* Material Properties */ + +void GPU_set_basic_material_shininess(int shininess) +{ + LIGHTING.material.shininess = CLAMPIS(shininess, 1, 128); +} + + + +void GPU_set_basic_material_specular(const float specular[4]) +{ + copy_v4_v4(LIGHTING.material.specular, specular); +} + + + +/* Light Properties */ + + + +void GPU_restore_basic_lights(int light_count, const GPUbasiclight lights[]) +{ + GPU_ASSERT(light_count >= 0); + GPU_ASSERT(light_count < GPU_MAX_COMMON_LIGHTS); + + memcpy(LIGHTING.light, lights, light_count*sizeof(GPUbasiclight)); + + LIGHTING.light_count = light_count; +} + + + +static void feedback_light_position(float position[4] /* in-out */) +{ + GPU_feedback_vertex_4fv(GL_MODELVIEW_MATRIX, position[0], position[1], position[2], position[3], position); +} + + + +static void feedback_spot_direction(float spot_direction[3] /* in-out */) +{ + float n[3][3]; + + copy_m3_m4(n, (float (*)[4])gpuGetMatrix(GL_MODELVIEW_MATRIX, NULL)); + mul_m3_v3(n, spot_direction); +} + + + +void GPU_set_basic_lights(int light_count, const GPUbasiclight lights[]) +{ + int i; + + GPU_restore_basic_lights(light_count, lights); + + for (i = 0; i < light_count; i++) { + feedback_light_position(LIGHTING.light[i].position); + feedback_spot_direction(LIGHTING.light[i].spot_direction); + } +} + + + +int GPU_get_basic_lights(GPUbasiclight lights_out[]) +{ + memcpy(lights_out, LIGHTING.light, LIGHTING.light_count*sizeof(GPUbasiclight)); + + return LIGHTING.light_count; +} diff --git a/source/blender/gpu/intern/gpu_lighting_intern.h b/source/blender/gpu/intern/gpu_lighting_intern.h new file mode 100644 index 00000000000..f25394b20d8 --- /dev/null +++ b/source/blender/gpu/intern/gpu_lighting_intern.h @@ -0,0 +1,53 @@ +#ifndef _GPU_LIGHTING_INTERN_H_ +#define _GPU_LIGHTING_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_lighting_intern.h + * \ingroup gpu + */ + +#include "GPU_lighting.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_lighting_init(void); +void gpu_lighting_exit(void); + +void gpu_commit_lighting(void); +void gpu_commit_material(void); + +bool gpu_lighting_is_fast(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_LIGHTING_H_ */ diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 81dcd9cf450..4f8ae3ebde8 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -31,11 +31,17 @@ * Manages materials, lights and textures. */ +/* my interface */ +#include "GPU_material.h" -#include <math.h> -#include <string.h> +/* my library */ +#include "GPU_extensions.h" +#include "GPU_glew.h" + +/* internal */ +#include "intern/gpu_codegen.h" -#include "GL/glew.h" +/* external */ #include "MEM_guardedalloc.h" @@ -62,12 +68,11 @@ #include "IMB_imbuf_types.h" -#include "GPU_extensions.h" -#include "GPU_material.h" +/* standard */ +#include <math.h> +#include <string.h> -#include "gpu_codegen.h" -#include <string.h> /* Structs */ @@ -196,7 +201,7 @@ static void gpu_material_set_attrib_id(GPUMaterial *material) attribs->totlayer = b; } -static int GPU_material_construct_end(GPUMaterial *material) +static bool GPU_material_construct_end(GPUMaterial *material) { if (material->outlink) { GPUNodeLink *outlink; @@ -207,10 +212,10 @@ static int GPU_material_construct_end(GPUMaterial *material) &material->attribs, &material->builtins, material->ma->id.name); if (!material->pass) - return 0; + return false; gpu_material_set_attrib_id(material); - + shader = GPU_pass_shader(material->pass); if (material->builtins & GPU_VIEW_MATRIX) @@ -225,10 +230,12 @@ static int GPU_material_construct_end(GPUMaterial *material) material->obcolloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBCOLOR)); if (material->builtins & GPU_AUTO_BUMPSCALE) material->obautobumpscaleloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_AUTO_BUMPSCALE)); - return 1; - } - return 0; + return true; + } + else { + return false; + } } void GPU_material_free(Material *ma) @@ -1051,10 +1058,10 @@ static void do_material_tex(GPUShadeInput *shi) texco= shi->ref; } else if (mtex->texco==TEXCO_UV) { - if (1) { //!(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) { + //if (!(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) { GPU_link(mat, "texco_uv", GPU_attribute(CD_MTFACE, mtex->uvname), &texco_uv); /*lastuvname = mtex->uvname;*/ /*UNUSED*/ - } + //} texco= texco_uv; } else @@ -2075,7 +2082,6 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) GPUMaterial *mat; GPUInputUniform *uniform; GPUInputAttribute *attribute; - GLint lastbindcode; int i, liblen, fraglen; if (!GPU_glsl_support()) @@ -2112,12 +2118,7 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) case GPU_TEX2D: if (GPU_texture_opengl_bindcode(input->tex)) { uniform->type = GPU_DYNAMIC_SAMPLER_2DBUFFER; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode); - glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(input->tex)); - uniform->texsize = GPU_texture_opengl_width(input->tex) * GPU_texture_opengl_height(input->tex); - uniform->texpixels = MEM_mallocN(uniform->texsize*4, "RGBApixels"); - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, uniform->texpixels); - glBindTexture(GL_TEXTURE_2D, lastbindcode); + uniform->texpixels = GPU_texture_dup_pixels(input->tex, &(uniform->texsize)); } break; } @@ -2235,4 +2236,3 @@ void GPU_free_shader_export(GPUShaderExport *shader) MEM_freeN(shader); } - diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c new file mode 100644 index 00000000000..dab468e6733 --- /dev/null +++ b/source/blender/gpu/intern/gpu_matrix.c @@ -0,0 +1,550 @@ +/* + * ***** 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 ipmlied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov, Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_matrix.c + * \ingroup gpu + */ + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + +/* my interface */ +#include "intern/gpu_matrix_intern.h" + +/* my library */ +#include "GPU_common.h" +#include "GPU_extensions.h" +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_common_intern.h" + +/* external */ + +#include "BLI_math_matrix.h" +#include "BLI_math_rotation.h" +#include "BLI_math_vector.h" + +#include "MEM_guardedalloc.h" + + + +typedef GLfloat GPU_matrix[4][4]; + +typedef struct GPU_matrix_stack +{ + GLsizei size; + GLsizei pos; + GPU_matrix* dynstack; +} GPU_matrix_stack; + + + +static GPU_matrix_stack ms_modelview; +static GPU_matrix_stack ms_projection; +static GPU_matrix_stack ms_texture; + +static GPU_matrix_stack* ms_current; +static GLenum ms_current_mode; + + + +#define current_matrix() (ms_current->dynstack[ms_current->pos]) + + + +/* Check if we have a good matrix */ +#ifdef WITH_GPU_SAFETY + +static void checkmat(GLfloat *m) +{ + GLint i; + + for(i = 0; i < 16; i++) { +#if _MSC_VER + GPU_ASSERT(_finite(m[i])); +#else + GPU_ASSERT(!isinf(m[i])); +#endif + } +} + +#define CHECKMAT(m) checkmat((GLfloat*)m) + +#else + +#define CHECKMAT(m) + +#endif + + + +static void ms_init(GPU_matrix_stack* ms, GLint initsize) +{ + BLI_assert(initsize > 0); + + ms->size = initsize; + ms->pos = 0; + ms->dynstack = (GPU_matrix*)MEM_mallocN(ms->size*sizeof(*(ms->dynstack)), "MatrixStack"); +} + + + +static void ms_free(GPU_matrix_stack * ms) +{ + ms->size = 0; + ms->pos = 0; + MEM_freeN(ms->dynstack); + ms->dynstack = NULL; +} + + + +void gpu_matrix_init(void) +{ + ms_init(&ms_texture, 16); + ms_init(&ms_projection, 16); + ms_init(&ms_modelview, 32); + + gpuMatrixMode(GL_TEXTURE); + gpuLoadIdentity(); + + gpuMatrixMode(GL_PROJECTION); + gpuLoadIdentity(); + + gpuMatrixMode(GL_MODELVIEW); + gpuLoadIdentity(); +} + +void gpu_matrix_exit(void) +{ + ms_free(&ms_modelview); + ms_free(&ms_projection); + ms_free(&ms_texture); + + ms_current_mode = 0; + ms_current = NULL; +} + + + +void gpu_commit_matrix(void) +{ + const struct GPUcommon* common = gpu_get_common(); + + GPU_CHECK_NO_ERROR(); + + if (common) { + int i; + + GLfloat (*m)[4] = (GLfloat (*)[4])gpuGetMatrix(GL_MODELVIEW_MATRIX, NULL); + GLfloat (*p)[4] = (GLfloat (*)[4])gpuGetMatrix(GL_PROJECTION_MATRIX, NULL); + + if (common->modelview_matrix != -1) + glUniformMatrix4fv(common->modelview_matrix, 1, GL_FALSE, m[0]); + + if (common->normal_matrix != -1) { + GLfloat n[3][3]; + copy_m3_m4(n, m); + invert_m3(n); + transpose_m3(n); + glUniformMatrix3fv(common->normal_matrix, 1, GL_FALSE, n[0]); + } + + if (common->modelview_matrix_inverse != -1) { + GLfloat i[4][4]; + invert_m4_m4(i, m); + glUniformMatrix4fv(common->modelview_matrix_inverse, 1, GL_FALSE, i[0]); + } + + if (common->modelview_projection_matrix != -1) { + GLfloat pm[4][4]; + mul_m4_m4m4(pm, p, m); + glUniformMatrix4fv(common->modelview_projection_matrix, 1, GL_FALSE, pm[0]); + } + + if (common->projection_matrix != -1) + glUniformMatrix4fv(common->projection_matrix, 1, GL_FALSE, p[0]); + + for (i = 0; i < GPU_MAX_COMMON_TEXCOORDS; i++) { + if (common->texture_matrix[i] != -1) { + GPU_set_common_active_texture(i); + glUniformMatrix4fv(common->texture_matrix[i], 1, GL_FALSE, gpuGetMatrix(GL_TEXTURE_MATRIX, NULL)); + } + } + + GPU_set_common_active_texture(0); + + GPU_CHECK_NO_ERROR(); + + return; + } + +#if defined(WITH_GL_PROFILE_COMPAT) + glMatrixMode(GL_TEXTURE); + glLoadMatrixf(gpuGetMatrix(GL_TEXTURE_MATRIX, NULL)); + + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(gpuGetMatrix(GL_PROJECTION_MATRIX, NULL)); + + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(gpuGetMatrix(GL_MODELVIEW_MATRIX, NULL)); +#endif + + GPU_CHECK_NO_ERROR(); +} + + + +void gpuPushMatrix(void) +{ + GLsizei new_pos = ms_current->pos + 1; + + GPU_ASSERT(new_pos < ms_current->size); + + if (new_pos < ms_current->size) { + ms_current->pos++; + + gpuLoadMatrix((GLfloat*)ms_current->dynstack[ms_current->pos-1]); + } +} + + + +void gpuPopMatrix(void) +{ + GPU_ASSERT(ms_current->pos != 0); + + if (ms_current->pos != 0) { + ms_current->pos--; + + CHECKMAT(ms_current); + } +} + + + +void gpuMatrixMode(GLenum mode) +{ + GPU_ASSERT(ELEM3(mode, GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)); + + ms_current_mode = mode; + + switch(mode) { + case GL_MODELVIEW: + ms_current = &ms_modelview; + break; + case GL_PROJECTION: + ms_current = &ms_projection; + break; + case GL_TEXTURE: + ms_current = &ms_texture; + break; + default: + /* ignore */ + break; + } +} + + + +GLenum gpuGetMatrixMode(void) +{ + return ms_current_mode; +} + + + +void gpuLoadMatrix(const GLfloat* m) +{ + copy_m4_m4(current_matrix(), (GLfloat (*)[4])m); + + CHECKMAT(ms_current); +} + + + +const GLfloat* gpuGetMatrix(GLenum type, GLfloat *m) +{ + GPU_matrix_stack* ms_select; + + GPU_ASSERT(ELEM3(type, GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX, GL_TEXTURE_MATRIX)); + + switch(type) { + case GL_MODELVIEW_MATRIX: + ms_select = &ms_modelview; + break; + case GL_PROJECTION_MATRIX: + ms_select = &ms_projection; + break; + case GL_TEXTURE_MATRIX: + ms_select = &ms_texture; + break; + default: + return NULL; + } + + if (m) { + copy_m4_m4((GLfloat (*)[4])m, ms_select->dynstack[ms_select->pos]); + return m; + } + else { + return (GLfloat*)(ms_select->dynstack[ms_select->pos]); + } +} + + + +void gpuLoadIdentity(void) +{ + unit_m4(current_matrix()); + + CHECKMAT(ms_current); +} + + + +void gpuTranslate(GLfloat x, GLfloat y, GLfloat z) +{ + translate_m4(current_matrix(), x, y, z); + + CHECKMAT(ms_current); +} + + + +void gpuScale(GLfloat x, GLfloat y, GLfloat z) +{ + scale_m4(current_matrix(), x, y, z); + + CHECKMAT(ms_current); +} + + + +void gpuMultMatrix(const GLfloat *m) +{ + GPU_matrix cm; + + copy_m4_m4(cm, current_matrix()); + mul_m4_m4m4_q(current_matrix(), cm, (GLfloat (*)[4])m); + + CHECKMAT(ms_current); +} + + + +void gpuMultMatrixd(const double *m) +{ + GLfloat mf[16]; + GLint i; + + for(i = 0; i < 16; i++) { + mf[i] = m[i]; + } + + gpuMultMatrix(mf); +} + + + +void gpuRotateVector(GLfloat deg, GLfloat vector[3]) +{ + float rm[3][3]; + GPU_matrix cm; + + axis_angle_to_mat3(rm, vector, DEG2RADF(deg)); + + copy_m4_m4(cm, current_matrix()); + mul_m4_m3m4_q(current_matrix(), cm, rm); + + CHECKMAT(ms_current); +} + + + +void gpuRotateAxis(GLfloat deg, char axis) +{ + rotate_m4(current_matrix(), axis, DEG2RADF(deg)); + + CHECKMAT(ms_current); +} + + + +void gpuRotateRight(char type) +{ + rotate_m4_right(current_matrix(), type); + + CHECKMAT(ms_current); +} + + + +void gpuLoadOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) +{ + mat4_ortho_set(current_matrix(), left, right, bottom, top, nearVal, farVal); + + CHECKMAT(ms_current); +} + + + +void gpuOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) +{ + GPU_matrix om; + + mat4_ortho_set(om, left, right, bottom, top, nearVal, farVal); + + gpuMultMatrix((GLfloat*)om); +} + + + +void gpuFrustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) +{ + GPU_matrix fm; + + mat4_frustum_set(fm, left, right, bottom, top, nearVal, farVal); + + gpuMultMatrix((GLfloat*) fm); +} + + + +void gpuLoadFrustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) +{ + mat4_frustum_set(current_matrix(), left, right, bottom, top, nearVal, farVal); + + CHECKMAT(ms_current); +} + + + +void gpuLookAt(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ) +{ + GPU_matrix cm; + GLfloat lookdir[3]; + GLfloat camup[3] = {upX, upY, upZ}; + + lookdir[0] = centerX - eyeX; + lookdir[1] = centerY - eyeY; + lookdir[2] = centerZ - eyeZ; + + mat4_look_from_origin(cm, lookdir, camup); + + gpuMultMatrix((GLfloat*) cm); + gpuTranslate(-eyeX, -eyeY, -eyeZ); +} + + + +void gpuProject(const GLfloat obj[3], const GLfloat model[16], const GLfloat proj[16], const GLint view[4], GLfloat win[3]) +{ + float v[4]; + + mul_v4_m4v3(v, (float(*)[4])model, obj); + mul_m4_v4((float(*)[4])proj, v); + + win[0]=view[0]+(view[2]*(v[0]+1))*0.5f; + win[1]=view[1]+(view[3]*(v[1]+1))*0.5f; + win[2]=(v[2]+1)*0.5f; +} + + + +GLboolean gpuUnProject(const GLfloat win[3], const GLfloat model[16], const GLfloat proj[16], const GLint view[4], GLfloat obj[3]) +{ + GLfloat pm[4][4]; + GLfloat in[4]; + GLfloat out[4]; + + mul_m4_m4m4(pm, (float(*)[4])proj, (float(*)[4])model); + + if (!invert_m4(pm)) { + return GL_FALSE; + } + + in[0]=win[0]; + in[1]=win[1]; + in[2]=win[2]; + in[3]=1; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - view[0]) / view[2]; + in[1] = (in[1] - view[1]) / view[3]; + + /* Map to range -1 to 1 */ + in[0] = 2 * in[0] - 1; + in[1] = 2 * in[1] - 1; + in[2] = 2 * in[2] - 1; + + mul_v4_m4v3(out, pm, in); + + if (out[3] == 0.0) { + return GL_FALSE; + } + else { + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + + obj[0] = out[0]; + obj[1] = out[1]; + obj[2] = out[2]; + + return GL_TRUE; + } +} + + + +void GPU_feedback_vertex_3fv(GLenum type, GLfloat x, GLfloat y, GLfloat z, GLfloat out[3]) +{ + GPU_matrix* m = (GPU_matrix*)gpuGetMatrix(type, NULL); + float in[3] = {x, y, z}; + mul_v3_m4v3(out, m[0], in); +} + + + +void GPU_feedback_vertex_4fv(GLenum type, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat out[3]) +{ + GPU_matrix* m = (GPU_matrix*)gpuGetMatrix(type, NULL); + float in[4] = {x, y, z, w}; + mul_v4_m4v4(out, m[0], in); +} + + + +void GPU_feedback_vertex_4dv(GLenum type, GLdouble x, GLdouble y, GLdouble z, GLdouble w, GLdouble out[3]) +{ + GPU_matrix* m = (GPU_matrix*)gpuGetMatrix(type, NULL); + double in[4] = {x, y, z, w}; + mul_v4d_m4v4d(out, m[0], in); +} diff --git a/source/blender/gpu/intern/gpu_matrix_intern.h b/source/blender/gpu/intern/gpu_matrix_intern.h new file mode 100644 index 00000000000..5c5dcc4fc43 --- /dev/null +++ b/source/blender/gpu/intern/gpu_matrix_intern.h @@ -0,0 +1,52 @@ +#ifndef _GPU_MATRIX_INTERN_H_ +#define _GPU_MATRIX_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Alexandr Kuznetsov, Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_matrix_itnern.h + * \ingroup gpu + */ + +#include "GPU_matrix.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_matrix_forced_update(void); + +void gpu_matrix_init(void); +void gpu_matrix_exit(void); + +void gpu_commit_matrix(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_MATRIX_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_pixels.c b/source/blender/gpu/intern/gpu_pixels.c new file mode 100644 index 00000000000..144c602759a --- /dev/null +++ b/source/blender/gpu/intern/gpu_pixels.c @@ -0,0 +1,636 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_pixels.c + * \ingroup gpu + */ + +/* my interface */ +#include "intern/gpu_pixels_intern.h" + +/* my library */ +#include "GPU_basic.h" +#include "GPU_blender_aspect.h" +#include "GPU_colors.h" +#include "GPU_extensions.h" +#include "GPU_immediate.h" +#include "GPU_matrix.h" +#include "GPU_safety.h" +#include "GPU_state_latch.h" + +/* internal */ +#include "intern/gpu_common_intern.h" +#include "intern/gpu_matrix_intern.h" +#include "intern/gpu_profile.h" + +/* external */ +#include "BLI_dynstr.h" + +#include "MEM_guardedalloc.h" + + + +static struct GPUShader* PIXELS_SHADER = NULL; +static struct GPUcommon PIXELS_COMMON = {0}; +static bool PIXELS_FAILED = false; + +static GLfloat PIXELS_POS[3] = { 0, 0, 0 }; + + +#if GPU_SAFETY +static bool PIXELS_BEGUN = false; +#endif + + + +void gpu_pixels_init(void) +{ + PIXELS_SHADER = NULL; +} + + + +void gpu_pixels_exit(void) +{ + GPU_shader_free(PIXELS_SHADER); +} + + + +void GPU_bitmap_cache(GPUbitmap* bitmap) +{ +} + + + +void GPU_pixels_cache(GPUpixels* pixels) +{ +} + + + +void GPU_bitmap_uncache(GPUbitmap* bitmap) +{ +} + + + +void GPU_pixels_uncache(GPUpixels* pixels) +{ +} + + + +static GLuint non_default_flags = 0; + +#define NON_DEFAULT_FACTOR (1 << 0) +#define NON_DEFAULT_RED_SCALE (1 << 1) +#define NON_DEFAULT_RED_BIAS (1 << 2) +#define NON_DEFAULT_GREEN_SCALE (1 << 3) +#define NON_DEFAULT_GREEN_BIAS (1 << 4) +#define NON_DEFAULT_BLUE_SCALE (1 << 5) +#define NON_DEFAULT_BLUE_BIAS (1 << 6) +#define NON_DEFAULT_ALPHA_SCALE (1 << 7) +#define NON_DEFAULT_ALPHA_BIAS (1 << 8) +#define NON_DEFAULT_UNPACK_ROW_LENGTH (1 << 9) +#define NON_DEFAULT_UNPACK_SWAP_BYTES (1 << 10) +#define NON_DEFAULT_UNPACK_ALIGNMENT (1 << 11) + + + +static GLint format_unpack_row_length = 0; +static GLboolean format_unpack_swap_bytes = GL_FALSE; +static GLint format_unpack_alignment = 4; + +void GPU_pixels_format(GLenum pname, GLint param) +{ + switch(pname) { + case GL_UNPACK_ROW_LENGTH: + format_unpack_row_length = param; + if (param == 0) + non_default_flags ^= NON_DEFAULT_UNPACK_ROW_LENGTH; + else + non_default_flags |= NON_DEFAULT_UNPACK_ROW_LENGTH; + + break; + + case GL_UNPACK_SWAP_BYTES: + format_unpack_swap_bytes = param; + if (param == 0) + non_default_flags ^= NON_DEFAULT_UNPACK_SWAP_BYTES; + else + non_default_flags |= NON_DEFAULT_UNPACK_SWAP_BYTES; + + break; + + case GL_UNPACK_ALIGNMENT: + format_unpack_alignment = param; + if (param == 0) + non_default_flags ^= NON_DEFAULT_UNPACK_ALIGNMENT; + else + non_default_flags |= NON_DEFAULT_UNPACK_ALIGNMENT; + + break; + + default: + GPU_ABORT(); + break; + } +} + + + +static GLfloat pixels_zoom_xfactor = 1; +static GLfloat pixels_zoom_yfactor = 1; + +void GPU_pixels_zoom(GLfloat xfactor, GLfloat yfactor) +{ + pixels_zoom_xfactor = xfactor; + pixels_zoom_yfactor = yfactor; + + if (xfactor == 1 || yfactor == 1) + non_default_flags ^= NON_DEFAULT_FACTOR; + else + non_default_flags |= NON_DEFAULT_FACTOR; +} + + + +void GPU_get_pixels_zoom(GLfloat* xfactor_out, GLfloat *yfactor_out) +{ + *xfactor_out = pixels_zoom_xfactor; + *yfactor_out = pixels_zoom_yfactor; +} + + + +static GLfloat pixels_scale_red = 1; +static GLfloat pixels_scale_green = 1; +static GLfloat pixels_scale_blue = 1; +static GLfloat pixels_scale_alpha = 1; + +static GLfloat pixels_bias_red = 0; +static GLfloat pixels_bias_green = 0; +static GLfloat pixels_bias_blue = 0; +static GLfloat pixels_bias_alpha = 0; + +// XXX jwilkins: this would be a lot shorter if you made a table + +void GPU_pixels_uniform_1f(GLenum pname, GLfloat param) +{ + switch(pname) { + case GL_RED_SCALE: + pixels_scale_red = param; + + if (param == 1) + non_default_flags ^= NON_DEFAULT_RED_SCALE; + else + non_default_flags |= NON_DEFAULT_RED_SCALE; + + break; + + case GL_RED_BIAS: + pixels_bias_red = param; + + if (param != 0) + non_default_flags ^= NON_DEFAULT_RED_BIAS; + else + non_default_flags |= NON_DEFAULT_RED_BIAS; + + break; + + case GL_BLUE_SCALE: + pixels_scale_blue = param; + + if (param != 1) + non_default_flags ^= NON_DEFAULT_BLUE_SCALE; + else + non_default_flags |= NON_DEFAULT_BLUE_SCALE; + + break; + + case GL_BLUE_BIAS: + pixels_bias_blue = param; + + if (param != 0) + non_default_flags ^= NON_DEFAULT_BLUE_BIAS; + else + non_default_flags |= NON_DEFAULT_BLUE_BIAS; + + break; + + case GL_GREEN_SCALE: + pixels_scale_green = param; + + if (param != 1) + non_default_flags ^= NON_DEFAULT_GREEN_SCALE; + else + non_default_flags |= NON_DEFAULT_GREEN_SCALE; + + break; + + case GL_GREEN_BIAS: + pixels_bias_green = param; + + if (param != 0) + non_default_flags ^= NON_DEFAULT_GREEN_BIAS; + else + non_default_flags |= NON_DEFAULT_GREEN_BIAS; + + break; + + case GL_ALPHA_SCALE: + pixels_scale_alpha = param; + + if (param != 1) + non_default_flags ^= NON_DEFAULT_ALPHA_SCALE; + else + non_default_flags |= NON_DEFAULT_ALPHA_SCALE; + + break; + + case GL_ALPHA_BIAS: + pixels_bias_alpha = param; + + if (param != 0) + non_default_flags ^= NON_DEFAULT_ALPHA_BIAS; + else + non_default_flags |= NON_DEFAULT_ALPHA_BIAS; + + break; + + default: + GPU_ABORT(); + break; + } +} + + + +static GLint location_scale; +static GLint location_bias; + +static void pixels_init_uniform_locations(void) +{ + location_scale = GPU_shader_get_uniform(PIXELS_SHADER, "b_Pixels.scale"); + location_bias = GPU_shader_get_uniform(PIXELS_SHADER, "b_Pixels.bias" ); +} + + + +static void commit_pixels(void) +{ + GPU_CHECK_NO_ERROR(); + glUniform4f(location_scale, pixels_scale_red, pixels_scale_green, pixels_scale_blue, pixels_scale_alpha); + glUniform4f(location_bias , pixels_bias_red, pixels_bias_green, pixels_bias_blue, pixels_bias_alpha ); + GPU_CHECK_NO_ERROR(); +} + + + +static void gpu_pixels_shader(void) +{ + /* GLSL code */ + extern const char datatoc_gpu_shader_pixels_uniforms_glsl[]; + extern const char datatoc_gpu_shader_pixels_vert_glsl[]; + extern const char datatoc_gpu_shader_pixels_frag_glsl[]; + + /* Create shader if it doesn't exist yet. */ + if (PIXELS_SHADER != NULL) { + GPU_shader_bind(PIXELS_SHADER); + gpu_set_common(&PIXELS_COMMON); + } + else if (!PIXELS_FAILED) { + DynStr* vert = BLI_dynstr_new(); + DynStr* frag = BLI_dynstr_new(); + DynStr* defs = BLI_dynstr_new(); + + char* vert_cstring; + char* frag_cstring; + char* defs_cstring; + + gpu_include_common_vert(vert); + BLI_dynstr_append(vert, datatoc_gpu_shader_pixels_uniforms_glsl); + BLI_dynstr_append(vert, datatoc_gpu_shader_pixels_vert_glsl); + + gpu_include_common_frag(frag); + BLI_dynstr_append(frag, datatoc_gpu_shader_pixels_uniforms_glsl); + BLI_dynstr_append(frag, datatoc_gpu_shader_pixels_frag_glsl); + + gpu_include_common_defs(defs); + BLI_dynstr_append(defs, "#define USE_TEXTURE_2D\n"); + + vert_cstring = BLI_dynstr_get_cstring(vert); + frag_cstring = BLI_dynstr_get_cstring(frag); + defs_cstring = BLI_dynstr_get_cstring(defs); + + PIXELS_SHADER = + GPU_shader_create("Pixels", vert_cstring, frag_cstring, NULL, defs_cstring); + + MEM_freeN(vert_cstring); + MEM_freeN(frag_cstring); + MEM_freeN(defs_cstring); + + BLI_dynstr_free(vert); + BLI_dynstr_free(frag); + BLI_dynstr_free(defs); + + if (PIXELS_SHADER != NULL) { + gpu_common_get_symbols(&PIXELS_COMMON, PIXELS_SHADER); + gpu_set_common(&PIXELS_COMMON); + + pixels_init_uniform_locations(); + + GPU_shader_bind(PIXELS_SHADER); + + commit_pixels(); /* only needs to be done once */ + } + else { + PIXELS_FAILED = true; + gpu_set_common(NULL); + } + } + else { + gpu_set_common(NULL); + } +} + + + +void gpu_pixels_bind(void) +{ + bool glsl_support = GPU_glsl_support(); + + if (glsl_support) + gpu_pixels_shader(); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (!glsl_support) + GPU_CHECK(glEnable(GL_TEXTURE_2D)); +#endif + + gpu_commit_matrix(); +} + + + +void gpu_pixels_unbind(void) +{ + bool glsl_support = GPU_glsl_support(); + + if (glsl_support) + GPU_shader_unbind(); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (!glsl_support) + GPU_CHECK(glDisable(GL_TEXTURE_2D)); +#endif +} + + + +void GPU_pixels_begin() +{ +#if GPU_SAFETY + GPU_ASSERT(!PIXELS_BEGUN); + PIXELS_BEGUN = true; +#endif + +#if defined(WITH_GL_PROFILE_COMPAT) + if (GPU_PROFILE_COMPAT) { + if (non_default_flags & NON_DEFAULT_RED_SCALE) glPixelTransferf(GL_RED_SCALE, pixels_scale_red); + if (non_default_flags & NON_DEFAULT_RED_BIAS) glPixelTransferf(GL_RED_BIAS, pixels_bias_red); + if (non_default_flags & NON_DEFAULT_GREEN_SCALE) glPixelTransferf(GL_BLUE_SCALE, pixels_scale_blue); + if (non_default_flags & NON_DEFAULT_GREEN_BIAS) glPixelTransferf(GL_BLUE_BIAS, pixels_bias_blue); + if (non_default_flags & NON_DEFAULT_BLUE_SCALE) glPixelTransferf(GL_GREEN_SCALE, pixels_scale_green); + if (non_default_flags & NON_DEFAULT_BLUE_BIAS) glPixelTransferf(GL_GREEN_BIAS, pixels_bias_green); + if (non_default_flags & NON_DEFAULT_ALPHA_SCALE) glPixelTransferf(GL_ALPHA_SCALE, pixels_scale_alpha); + if (non_default_flags & NON_DEFAULT_ALPHA_BIAS) glPixelTransferf(GL_ALPHA_BIAS, pixels_bias_alpha); + + if (non_default_flags & NON_DEFAULT_FACTOR) glPixelZoom(pixels_zoom_xfactor, pixels_zoom_yfactor); + + if (non_default_flags & NON_DEFAULT_UNPACK_ROW_LENGTH) glPixelStorei(GL_UNPACK_ROW_LENGTH, format_unpack_row_length); + if (non_default_flags & NON_DEFAULT_UNPACK_SWAP_BYTES) glPixelStorei(GL_UNPACK_SWAP_BYTES, format_unpack_swap_bytes); + if (non_default_flags & NON_DEFAULT_UNPACK_ALIGNMENT) glPixelStorei(GL_UNPACK_ALIGNMENT, format_unpack_alignment); + } +#endif + + // SSS End (Assuming the basic aspect is ending) + GPU_aspect_end(); + + // SSS Begin Pixels + GPU_aspect_begin(GPU_ASPECT_PIXELS, NULL); +} + + + +void GPU_pixels_end() +{ +#if GPU_SAFETY + GPU_ASSERT(PIXELS_BEGUN); +#endif + +#if defined(WITH_GL_PROFILE_COMPAT) + if (GPU_PROFILE_COMPAT) { + GPU_CHECK_NO_ERROR(); + + if (non_default_flags & NON_DEFAULT_RED_SCALE) + glPixelTransferf(GL_RED_SCALE, 1); + + if (non_default_flags & NON_DEFAULT_RED_BIAS) + glPixelTransferf(GL_RED_BIAS, 0); + + if (non_default_flags & NON_DEFAULT_GREEN_SCALE) + glPixelTransferf(GL_BLUE_SCALE, 1); + + if (non_default_flags & NON_DEFAULT_GREEN_BIAS) + glPixelTransferf(GL_BLUE_BIAS, 0); + + if (non_default_flags & NON_DEFAULT_BLUE_SCALE) + glPixelTransferf(GL_GREEN_SCALE, 1); + + if (non_default_flags & NON_DEFAULT_BLUE_BIAS) + glPixelTransferf(GL_GREEN_BIAS, 0); + + if (non_default_flags & NON_DEFAULT_ALPHA_SCALE) + glPixelTransferf(GL_ALPHA_SCALE, 1); + + if (non_default_flags & NON_DEFAULT_ALPHA_BIAS) + glPixelTransferf(GL_ALPHA_BIAS, 0); + + if (non_default_flags & NON_DEFAULT_FACTOR) + glPixelZoom(1, 1); + + if (non_default_flags & NON_DEFAULT_UNPACK_ROW_LENGTH) + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + if (non_default_flags & NON_DEFAULT_UNPACK_ALIGNMENT) + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + if (non_default_flags & NON_DEFAULT_UNPACK_ROW_LENGTH) + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + + GPU_CHECK_NO_ERROR(); + } +#endif + + // SSS End Pixels + GPU_aspect_end(); + +#if GPU_SAFETY + PIXELS_BEGUN = false; +#endif + + // SSS Begin Basic + GPU_aspect_begin(GPU_ASPECT_BASIC, NULL); +} + + + +#if defined(WITH_GL_PROFILE_COMPAT) +/** + * Functions like glRasterPos2i, except ensures that the resulting + * raster position is valid. \a known_good_x and \a known_good_y + * should be coordinates of a point known to be within the current + * view frustum. + * \attention This routine should be used when the distance of \a x + * and \a y away from the known good point is small (ie. for small icons + * and for bitmap characters), when drawing large+zoomed images it is + * possible for overflow to occur, the glaDrawPixelsSafe routine should + * be used instead. + */ +static void raster_pos_safe_2f(float x, float y, float known_good_x, float known_good_y) +{ + GLubyte dummy = 0; + + GPU_CHECK_NO_ERROR(); + + /* As long as known good coordinates are correct + * this is guaranteed to generate an ok raster + * position (ignoring potential (real) overflow + * issues). + */ + glRasterPos2f(known_good_x, known_good_y); + + /* Now shift the raster position to where we wanted + * it in the first place using the glBitmap trick. + */ + glBitmap(0, 0, 0, 0, x - known_good_x, y - known_good_y, &dummy); + + GPU_CHECK_NO_ERROR(); +} +#endif + + + +void GPU_pixels_pos_2f(GLfloat x, GLfloat y) +{ +#if defined(WITH_GL_PROFILE_COMPAT) + /* Don't use safe RasterPos (slower) if we can avoid it. */ + if (x >= 0 && y >= 0) + glRasterPos2f(x, y); + else + raster_pos_safe_2f(x, y, 0, 0); +#endif + +#if defined(WITH_GL_PROFILE_CORE) || defined(WITH_GL_PROFILE_ES20) + VEC3D(PIXELS_POS, x, y, 0); +#endif +} + + + +void GPU_pixels_pos_3f(GLfloat x, GLfloat y, GLfloat z) +{ +#if defined(WITH_GL_PROFILE_COMPAT) + glRasterPos3fv(PIXELS_POS); +#endif + +#if defined(WITH_GL_PROFILE_CORE) || defined(WITH_GL_PROFILE_ES20) + VEC3D(PIXELS_POS, x, y, z); +#endif +} + + + +void GPU_bitmap(GPUbitmap* bitmap) +{ + GPU_ASSERT(PIXELS_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (GPU_PROFILE_COMPAT) { + glBitmap( + bitmap->width, + bitmap->height, + bitmap->xorig, + bitmap->yorig, + 0, + 0, + bitmap->bitmap); + } +#endif +} + + + +extern void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, const void *rect, float scaleX, float scaleY); + +void GPU_pixels(GPUpixels* pixels) +{ + GPU_ASSERT(PIXELS_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (GPU_PROFILE_COMPAT) { + GPU_CHECK( + glDrawPixels( + pixels->width, + pixels->height, + pixels->format, + pixels->type, + pixels->pixels)); + + return; + } +#endif + +#if defined(WITH_GL_PROFILE_ES20) || defined(WITH_GL_PROFILE_CORE) + if (GPU_PROFILE_ES20 || GPU_PROFILE_CORE) { + glaDrawPixelsTexScaled( + PIXELS_POS[0], + PIXELS_POS[1], + pixels->width, + pixels->height, + pixels->format, + pixels->type, + GL_NEAREST, + pixels->pixels, + 1, + 1); + return; + } +#endif +} diff --git a/source/blender/gpu/intern/gpu_pixels_intern.h b/source/blender/gpu/intern/gpu_pixels_intern.h new file mode 100644 index 00000000000..c1db0452a7e --- /dev/null +++ b/source/blender/gpu/intern/gpu_pixels_intern.h @@ -0,0 +1,51 @@ +#ifndef _GPU_PIXELS_INTERN_H_ +#define _GPU_PIXELS_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_pixels_intern.h + * \ingroup gpu + */ + +#include "GPU_pixels.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_pixels_init(void); +void gpu_pixels_exit(void); + +void gpu_pixels_bind (void); +void gpu_pixels_unbind(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_PIXELS_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_primitives.c b/source/blender/gpu/intern/gpu_primitives.c new file mode 100644 index 00000000000..c088a5e633a --- /dev/null +++ b/source/blender/gpu/intern/gpu_primitives.c @@ -0,0 +1,1328 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file GPU_lighting.c + * \ingroup gpu + */ + +#include "GPU_primitives.h" +#include "GPU_primitives.h" + +#include "BLI_math_vector.h" + + + +void gpuSingleLinef(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + gpuImmediateFormat_V2(); + gpuDrawLinef(x1, y1, x2, y2); + gpuImmediateUnformat(); +} + +void gpuSingleLinei(GLint x1, GLint y1, GLint x2, GLint y2) +{ + gpuImmediateFormat_V2(); + gpuDrawLinei(x1, y1, x2, y2); + gpuImmediateUnformat(); +} + + + +void gpuSingleFilledRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + gpuImmediateFormat_V2(); + gpuDrawFilledRectf(x1, y1, x2, y2); + gpuImmediateUnformat(); +} + +void gpuSingleFilledRecti(GLint x1, GLint y1, GLint x2, GLint y2) +{ + gpuImmediateFormat_V2(); + gpuDrawFilledRecti(x1, y1, x2, y2); + gpuImmediateUnformat(); +} + + + +void gpuSingleWireRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + gpuImmediateFormat_V2(); + gpuDrawWireRectf(x1, y1, x2, y2); + gpuImmediateUnformat(); +} + +void gpuSingleWireRecti(GLint x1, GLint y1, GLint x2, GLint y2) +{ + gpuImmediateFormat_V2(); + gpuDrawWireRecti(x1, y1, x2, y2); + gpuImmediateUnformat(); +} + + + +//void gpuAppendLitSweep( +// GLfloat x, +// GLfloat y, +// GLfloat z, +// GLfloat height, +// GLfloat radiusBot, +// GLfloat radiusTop, +// GLfloat startAngle, +// GLfloat sweepAngle, +// GLint sectors) +//{ +// int i; +// +// const GLfloat dr = radiusTop - radiusBot; +// const GLfloat zheight = z+height; +// GLfloat nz = cosf(atan2(height, dr)); +// GLfloat ns = 1.0f / sqrtf(nz*nz + 1); +// +// GPU_ASSERT(sectors > 0); +// +// for (i = 0; i <= sectors; i++) { +// GLfloat a = startAngle + i * sweepAngle / sectors; +// GLfloat c = cosf(a); +// GLfloat s = sinf(a); +// GLfloat n[3] = { c, s, nz }; +// +// mul_v3_fl(n, ns); +// +// if (normals) { +// glNormal3fv(n); +// } +// +// glVertex3f(radiusBot * c + x, radiusBot * s + y, z); +// +// if (normals) { +// glNormal3fv(n); +// } +// +// glVertex3f(radiusTop * c + x, radiusTop * s + y, zheight); +// } +//} + + + +void gpuAppendArc( + GLfloat x, + GLfloat y, + GLfloat start, + GLfloat angle, + GLfloat xradius, + GLfloat yradius, + GLint nsegments) +{ + int i; + + GPU_CHECK_MODE(GL_LINE_STRIP); + + GPU_ASSERT(nsegments > 0); + + for (i = 0; i <= nsegments; i++) { + const GLfloat t = (GLfloat)i / (GLfloat)nsegments; + GLfloat cur = t*angle + start; + + gpuVertex2f(cosf(cur)*xradius + x, sinf(cur)*yradius + y); + } +} + +void gpuDrawArc( + GLfloat x, + GLfloat y, + GLfloat start, + GLfloat angle, + GLfloat xradius, + GLfloat yradius, + GLint nsegments) +{ + gpuBegin(GL_LINE_STRIP); + gpuAppendArc(x, y, start, angle, xradius, yradius, nsegments); + gpuEnd(); +} + +void gpuSingleArc( + GLfloat x, + GLfloat y, + GLfloat start, + GLfloat angle, + GLfloat xradius, + GLfloat yradius, + GLint nsegments) +{ + gpuImmediateFormat_V2(); + gpuDrawArc(x, y, start, angle, xradius, yradius, nsegments); + gpuImmediateUnformat(); +} + + +void gpuImmediateSingleDraw(GLenum mode, GPUimmediate *__restrict immediate) +{ + GPUimmediate* oldImmediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE = immediate; + gpuImmediateLock(); + gpuDraw(mode); + gpuImmediateUnlock(); + GPU_IMMEDIATE = oldImmediate; +} + +void gpuImmediateSingleRepeat(GPUimmediate *__restrict immediate) +{ + GPUimmediate* oldImmediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE = immediate; + gpuImmediateLock(); + gpuRepeat(); + gpuImmediateUnlock(); + GPU_IMMEDIATE = oldImmediate; +} + +void gpuImmediateSingleDrawElements(GLenum mode, GPUimmediate *__restrict immediate) +{ + GPUimmediate* oldImmediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE = immediate; + gpuImmediateLock(); + gpuDrawElements(mode); + gpuImmediateUnlock(); + GPU_IMMEDIATE = oldImmediate; +} + +void gpuImmediateSingleRepeatElements(GPUimmediate *__restrict immediate) +{ + GPUimmediate* oldImmediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE = immediate; + gpuImmediateLock(); + gpuRepeatElements(); + gpuImmediateUnlock(); + GPU_IMMEDIATE = oldImmediate; +} + +void gpuImmediateSingleDrawRangeElements(GLenum mode, GPUimmediate *__restrict immediate) +{ + GPUimmediate* oldImmediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE = immediate; + gpuImmediateLock(); + gpuDrawRangeElements(mode); + gpuImmediateUnlock(); + GPU_IMMEDIATE = oldImmediate; +} + +void gpuImmediateSingleRepeatRangeElements(GPUimmediate *__restrict immediate) +{ + GPUimmediate* oldImmediate = GPU_IMMEDIATE; + + GPU_IMMEDIATE = immediate; + gpuImmediateLock(); + gpuRepeatRangeElements(); + gpuImmediateUnlock(); + GPU_IMMEDIATE = oldImmediate; +} + +/* ----------------- OpenGL Circle Drawing - Tables for Optimized Drawing Speed ------------------ */ +/* 32 values of sin function (still same result!) */ +#define CIRCLE_RESOL 32 + +static const GLfloat sinval[CIRCLE_RESOL] = { + 0.00000000, + 0.20129852, + 0.39435585, + 0.57126821, + 0.72479278, + 0.84864425, + 0.93775213, + 0.98846832, + 0.99871650, + 0.96807711, + 0.89780453, + 0.79077573, + 0.65137248, + 0.48530196, + 0.29936312, + 0.10116832, + -0.10116832, + -0.29936312, + -0.48530196, + -0.65137248, + -0.79077573, + -0.89780453, + -0.96807711, + -0.99871650, + -0.98846832, + -0.93775213, + -0.84864425, + -0.72479278, + -0.57126821, + -0.39435585, + -0.20129852, + 0.00000000 +}; + +/* 32 values of cos function (still same result!) */ +static const GLfloat cosval[CIRCLE_RESOL] = { + 1.00000000, + 0.97952994, + 0.91895781, + 0.82076344, + 0.68896691, + 0.52896401, + 0.34730525, + 0.15142777, + -0.05064916, + -0.25065253, + -0.44039415, + -0.61210598, + -0.75875812, + -0.87434661, + -0.95413925, + -0.99486932, + -0.99486932, + -0.95413925, + -0.87434661, + -0.75875812, + -0.61210598, + -0.44039415, + -0.25065253, + -0.05064916, + 0.15142777, + 0.34730525, + 0.52896401, + 0.68896691, + 0.82076344, + 0.91895781, + 0.97952994, + 1.00000000 +}; + +/* draws a circle on x-z plane given the scaling of the circle, assuming that + * all required matrices have been set (used for drawing empties) + */ +void gpuAppendFastCircleXZ(GLfloat radius) +{ + int i; + + /* coordinates are: cos(i*11.25) = x, 0 = y, sin(i*11.25) = z */ + for (i = 0; i < CIRCLE_RESOL; i++) { + gpuVertex3f(cosval[i] * radius, 0, sinval[i] * radius); + } +} + +void gpuAppendFastCircleXY(GLfloat radius) +{ + int i; + + /* coordinates are: cos(i*11.25) = x, sin(i*11.25) = y, z=0 */ + for (i = 0; i < CIRCLE_RESOL; i++) { + gpuVertex3f(cosval[i] * radius, sinval[i] * radius, 0); + } +} + + +void gpuDrawFastCircleXZ(GLfloat radius) +{ + gpuBegin(GL_LINE_LOOP); + gpuAppendFastCircleXZ(radius); + gpuEnd(); +} + +void gpuDrawFastCircleXY(GLfloat radius) +{ + gpuBegin(GL_LINE_LOOP); + gpuAppendFastCircleXY(radius); + gpuEnd(); +} + +void gpuSingleFastCircleXZ(GLfloat radius) +{ + gpuImmediateFormat_V3(); + gpuDrawFastCircleXZ(radius); + gpuImmediateUnformat(); +} + +void gpuSingleFastCircleXY(GLfloat radius) +{ + gpuImmediateFormat_V3(); + gpuDrawFastCircleXY(radius); + gpuImmediateUnformat(); +} + +void gpuAppendFastBall( + const GLfloat position[3], + GLfloat radius, + const GLfloat matrix[4][4]) +{ + GLfloat vx[3], vy[3]; + GLuint a; + + mul_v3_v3fl(vx, matrix[0], radius); + mul_v3_v3fl(vy, matrix[1], radius); + + for (a = 0; a < CIRCLE_RESOL; a++) { + gpuVertex3f( + position[0] + sinval[a] * vx[0] + cosval[a] * vy[0], + position[1] + sinval[a] * vx[1] + cosval[a] * vy[1], + position[2] + sinval[a] * vx[2] + cosval[a] * vy[2]); + } +} + +void gpuDrawFastBall( + int mode, + const GLfloat position[3], + GLfloat radius, + const GLfloat matrix[4][4]) +{ + gpuBegin(mode); + gpuAppendFastBall(position, radius, matrix); + gpuEnd(); +} + +void gpuSingleFastBall( + int mode, + const GLfloat position[3], + GLfloat radius, + const GLfloat matrix[4][4]) +{ + gpuImmediateFormat_V3(); + gpuBegin(mode); + gpuAppendFastBall(position, radius, matrix); + gpuEnd(); + gpuImmediateUnformat(); +} + +void gpuAppendSpiral( + const GLfloat position[3], + GLfloat radius, + const GLfloat matrix[4][4], + int start) +{ + GLfloat vec[3], vx[3], vy[3]; + const GLfloat tot_inv = (1.0f / (GLfloat)CIRCLE_RESOL); + int a; + char inverse = false; + GLfloat x, y, fac; + + if (start < 0) { + inverse = true; + start = -start; + } + + mul_v3_v3fl(vx, matrix[0], radius); + mul_v3_v3fl(vy, matrix[1], radius); + + if (inverse == 0) { + copy_v3_v3(vec, position); + gpuVertex3fv(vec); + + for (a = 0; a < CIRCLE_RESOL; a++) { + if (a + start >= CIRCLE_RESOL) + start = -a + 1; + + fac = (GLfloat)a * tot_inv; + x = sinval[a + start] * fac; + y = cosval[a + start] * fac; + + vec[0] = position[0] + (x * vx[0] + y * vy[0]); + vec[1] = position[1] + (x * vx[1] + y * vy[1]); + vec[2] = position[2] + (x * vx[2] + y * vy[2]); + + gpuVertex3fv(vec); + } + } + else { + fac = (GLfloat)(CIRCLE_RESOL - 1) * tot_inv; + x = sinval[start] * fac; + y = cosval[start] * fac; + + vec[0] = position[0] + (x * vx[0] + y * vy[0]); + vec[1] = position[1] + (x * vx[1] + y * vy[1]); + vec[2] = position[2] + (x * vx[2] + y * vy[2]); + + gpuVertex3fv(vec); + + for (a = 0; a < CIRCLE_RESOL; a++) { + if (a + start >= CIRCLE_RESOL) + start = -a + 1; + + fac = (GLfloat)(-a + (CIRCLE_RESOL - 1)) * tot_inv; + x = sinval[a + start] * fac; + y = cosval[a + start] * fac; + + vec[0] = position[0] + (x * vx[0] + y * vy[0]); + vec[1] = position[1] + (x * vx[1] + y * vy[1]); + vec[2] = position[2] + (x * vx[2] + y * vy[2]); + gpuVertex3fv(vec); + } + } +} + +void gpuDrawSpiral( + const GLfloat position[3], + GLfloat radius, + GLfloat matrix[4][4], + int start) +{ + gpuBegin(GL_LINE_STRIP); + gpuAppendSpiral(position, radius, matrix, start); + gpuEnd(); +} + +void gpuSingleSpiral( + const GLfloat position[3], + GLfloat radius, + GLfloat matrix[4][4], + int start) +{ + gpuImmediateFormat_V3(); + gpuDrawSpiral(position, radius, matrix, start); + gpuImmediateUnformat(); +} + +void gpuAppendDisk( + GLfloat x, + GLfloat y, + GLfloat radius, + GLint nsectors) +{ + int i; + GLfloat x0 = 0, y0 = 0; + GLfloat x1, y1; + + GPU_CHECK_MODE(GL_TRIANGLES); + GPU_ASSERT(nsectors > 0); + + for (i = 0; i <= nsectors; i++) { + GLfloat angle = (GLfloat)(2.0*i*M_PI / nsectors); + + GLfloat c = cosf(angle)*radius + x; + GLfloat s = sinf(angle)*radius + y; + + if (i == 0) { + x0 = c; + y0 = s; + } + else { + x1 = c; + y1 = s; + + gpuVertex2f(x, y); + gpuVertex2f(x0, y0); + gpuVertex2f(x1, y1); + + x0 = x1; + y0 = y1; + } + } +} + +void gpuDrawDisk( + GLfloat x, + GLfloat y, + GLfloat radius, + GLint nsectors) +{ + gpuBegin(GL_TRIANGLES); + gpuAppendDisk(x, y, radius, nsectors); + gpuEnd(); +} + +void gpuSingleDisk( + GLfloat x, + GLfloat y, + GLfloat radius, + GLint nsectors) +{ + gpuImmediateFormat_V3(); + gpuDrawDisk(x, y, radius, nsectors); + gpuImmediateUnformat(); +} + + +// lit, solid, wire, solid w/ base, solid w/ end caps +//void gpuAppendCone(GLfloat radiusBase, GLfloat height, GLint ) +//{ +// int i; +// +// GPU_CHECK_MODE(GL_TRIANGLES); +// GPU_ASSERT(nsectors > 0); +// +// for (i = 0; i <= nsectors; i++) { +// GLfloat x0, y0; +// GLfloat x1, y1; +// GLfloat angle = (GLfloat)(2.0*i*M_PI / nsectors); +// +// GLfloat c = cosf(angle)*radius + x; +// GLfloat s = sinf(angle)*radius + y; +// +// if (i == 0) { +// x0 = c; +// y0 = s; +// } +// else { +// x1 = c; +// y1 = s; +// +// gpuVertex2f(x, y); +// gpuVertex2f(x0, y0); +// gpuVertex2f(x1, y1); +// +// x0 = x1; +// y0 = y1; +// } +// } +//} +// +//void gpuAppendCylinder() +//{ +//} + + + +BLI_INLINE void primFormat(GPUprim3 *prim) +{ + GPU_ASSERT( + ELEM3(prim->normals, + GPU_NORMALS_SMOOTH, + GPU_NORMALS_FLAT, + GPU_NORMALS_NONE)); + + switch (prim->normals) { + case GPU_NORMALS_NONE: + gpuImmediateFormat_V3(); + break; + + case GPU_NORMALS_SMOOTH: + case GPU_NORMALS_FLAT: + default: + gpuImmediateFormat_N3_V3(); + break; + } +} + +BLI_INLINE void primDraw(GPUprim3 *prim) +{ + GPU_ASSERT( + ELEM4(prim->drawStyle, + GPU_DRAW_STYLE_FILL, + GPU_DRAW_STYLE_SILHOUETTE, + GPU_DRAW_STYLE_LINES, + GPU_DRAW_STYLE_POINTS)); + + switch (prim->drawStyle) { + case GPU_DRAW_STYLE_FILL: + gpuDrawElements(GL_TRIANGLES); + break; + + case GPU_DRAW_STYLE_SILHOUETTE: + case GPU_DRAW_STYLE_LINES: + gpuDrawElements(GL_LINES); + break; + + case GPU_DRAW_STYLE_POINTS: + gpuDraw(GL_POINTS); + break; + + default: + break; + } +} + +static GLfloat sweep(GPUprim3* prim, GLfloat z) +{ + float l[3]; + float l0[3]; + float lz; + float d; + float x[3]; + float p0[3]; + float r[3]; + + copy_v3_v3(l0, prim->params.sweep.point1); + sub_v3_v3v3(l, prim->params.sweep.point2, l0); + lz = prim->params.sweep.point1[2]; + d = (z - lz) / l[2]; + madd_v3_v3v3fl(x, l0, l, d); + copy_v3_flflfl(p0, 0, 0, z); + sub_v3_v3v3(r, p0, x); + return len_v3(r); +} + +static GLfloat sphere(GPUprim3* prim, GLfloat z) +{ + float a = z / prim->params.sphere.radius; + float b = asinf(a); + return prim->params.sphere.radius * cosf(b); +} + +static void sphereNormals( + GLfloat no[GPU_MAX_SEGS+1][GPU_MAX_SEGS+1][3], + GLfloat co[GPU_MAX_SEGS+1][GPU_MAX_SEGS+1][3], + int usegs, + int vsegs) +{ + int i, j; + + for (j = 0; j <= vsegs; j++) { + for (i = 0; i <= usegs; i++) { + normalize_v3_v3(no[j][i], co[j][i]); + } + } +} + +BLI_INLINE float modfi(float a, int *b) +{ + double c, d; + d = modf(a, &c); + *b = (int)c; + return d; +} + +typedef void (*calc_normals_func)( + GLfloat out[GPU_MAX_SEGS+1][GPU_MAX_SEGS+1][3], + GLfloat pos[GPU_MAX_SEGS+1][GPU_MAX_SEGS+1][3], + int usegs, + int vsegs); + +BLI_INLINE void shape3( + GPUprim3* prim, + GLfloat (*radius)(GPUprim3* prim, GLfloat z), + calc_normals_func calc_normals, + GLfloat zMin, + GLfloat zMax, + GLboolean linearV) +{ + GLfloat uArc[GPU_MAX_SEGS+1][2]; + GLfloat vArc[GPU_MAX_SEGS+1]; + GLfloat co[GPU_MAX_SEGS+1][GPU_MAX_SEGS+1][3]; + GLfloat no[GPU_MAX_SEGS+1][GPU_MAX_SEGS+1][3]; + GLfloat uFracSegs; + int uWholeSegs; + GLfloat vFracSegs; + int vWholeSegs; + GLfloat sweepAngle; + GLfloat uFracAngle; + GLfloat z; + GLfloat r; + int usegs, vsegs; + int i, uIndex; + int j, vIndex; + GLboolean uCycle; + GLushort base; + GLboolean doNormals; + + + uFracSegs = modfi(prim->usegs, &uWholeSegs); + + sweepAngle = prim->thetaMax - prim->thetaMin; + + uFracAngle = (uFracSegs/2) * (sweepAngle/(prim->usegs)); + + uIndex = 0; + + if (uFracAngle != 0) { + copy_v2_flfl(uArc[uIndex++], cosf(prim->thetaMin), sinf(prim->thetaMin)); + } + + for (i = 0; i <= uWholeSegs; i++) { + GLfloat a = prim->thetaMin + uFracAngle + i*sweepAngle/(prim->usegs); + + copy_v2_flfl(uArc[uIndex++], cosf(a), sinf(a)); + } + + if (uFracSegs == 0) { + usegs = uIndex - 1; + } + else { + usegs = uIndex; + copy_v2_flfl(uArc[usegs], cosf(prim->thetaMax), sinf(prim->thetaMax)); + } + + uCycle = + fabs(uArc[usegs][0] - uArc[0][0]) < 0.001f && + fabs(uArc[usegs][1] - uArc[0][1]) < 0.001f; + + if (uCycle) { + usegs--; + } + + vFracSegs = modfi(prim->vsegs, &vWholeSegs); + + if (linearV) { + GLfloat sweepHeight; + GLfloat vFracHeight; + + sweepHeight = zMax - zMin; + + vFracHeight = (vFracSegs/2) * (sweepHeight/(prim->vsegs)); + + vIndex = 0; + + if (vFracHeight != 0) { + vArc[vIndex++] = zMin; + } + + for (j = 0; j <= vWholeSegs; j++) { + vArc[vIndex++] = zMin + vFracHeight + j*sweepHeight/(prim->vsegs); + } + } + else { + GLfloat angleMin; + GLfloat angleMax; + GLfloat vSweepAngle; + GLfloat zMinNorm; + GLfloat zMaxNorm; + GLfloat vFracAngle; + GLfloat zDiff; + + zMinNorm = zMin / prim->params.sphere.radius; + angleMin = asinf(zMinNorm); + + zMaxNorm = zMax / prim->params.sphere.radius; + angleMax = asinf(zMaxNorm); + + vSweepAngle = angleMax - angleMin; + + vFracAngle = (vFracSegs/2) * (vSweepAngle/(prim->vsegs)); + + zDiff = (zMax - zMin) / 2; + + vIndex = 0; + + if (vFracAngle != 0) { + vArc[vIndex++] = zMin; + } + + for (j = 0; j <= vWholeSegs; j++) { + GLfloat a = angleMin + vFracAngle + j*vSweepAngle/(prim->vsegs); + vArc[vIndex++] = zDiff*sinf(a); + } + } + + if (vFracSegs == 0) { + vsegs = vIndex - 1; + } + else { + vsegs = vIndex; + vArc[vsegs] = zMax; + } + + for (j = 0; j <= vsegs; j++) { + z = vArc[j]; + r = radius(prim, z); + + for (i = 0; i <= usegs; i++) { + copy_v3_flflfl(co[j][i], r*uArc[i][0], r*uArc[i][1], z); + } + } + + doNormals = calc_normals && prim->normals != GPU_NORMALS_NONE; + + if (doNormals) { + calc_normals(no, co, usegs, vsegs); + } + + for (j = 0; j <= vsegs; j++) { + for (i = 0; i <= usegs; i++) { + if (doNormals) { + gpuNormal3fv(no[j][i]); + } + + gpuVertex3fv(co[j][i]); + } + } + + gpuIndexBegin(GL_UNSIGNED_SHORT); + + switch (prim->drawStyle) { + case GPU_DRAW_STYLE_FILL: + for (j = 0; j < vsegs; j++) { + base = (usegs+1) * j; + for (i = 0; i < usegs; i++) { + if (prim->normals == GPU_NORMALS_FLAT || (i+j) % 2 == 0) { + gpuIndexus(base+1); + gpuIndexus(base+usegs+2); + gpuIndexus(base); + + gpuIndexus(base+usegs+2); + gpuIndexus(base+usegs+1); + gpuIndexus(base); + } + else { + gpuIndexus(base+1); + gpuIndexus(base+usegs+1); + gpuIndexus(base); + + gpuIndexus(base+usegs+2); + gpuIndexus(base+usegs+1); + gpuIndexus(base+1); + } + + base++; + } + } + + if (uCycle) { + base = usegs; + + for (j = 0; j < vsegs; j++) { + if (prim->normals == GPU_NORMALS_FLAT || (usegs+j) % 2 == 0) { + gpuIndexus(base-usegs); + gpuIndexus(base+1); + gpuIndexus(base); + + gpuIndexus(base+1); + gpuIndexus(base+usegs+1); + gpuIndexus(base); + } + else { + gpuIndexus(base); + gpuIndexus(base-usegs); + gpuIndexus(base+usegs+1); + + gpuIndexus(base+usegs+1); + gpuIndexus(base-usegs); + gpuIndexus(base+1); + } + + base += usegs+1; + } + } + + break; + + case GPU_DRAW_STYLE_SILHOUETTE: + for (j = 0; j < vsegs; j++) { + base = (usegs+1) * j; + for (i = 0; i < usegs; i++) { + gpuIndexus(base+usegs+1); + gpuIndexus(base); + + gpuIndexus(base+1); + gpuIndexus(base); + + base++; + } + } + + base = (usegs+1) * vsegs; + + for (i = 0; i < usegs; i++) { + gpuIndexus(base+1); + gpuIndexus(base); + + base++; + } + + base = usegs; + + for (j = 0; j < vsegs; j++) { + gpuIndexus(base+usegs+1); + gpuIndexus(base); + + if (uCycle) { + gpuIndexus(base-usegs); + gpuIndexus(base); + } + + base += usegs+1; + } + + if (uCycle) { + gpuIndexus(base-usegs); + gpuIndexus(base); + } + + break; + + case GPU_DRAW_STYLE_LINES: + for (j = 0; j < vsegs; j++) { + base = (usegs+1) * j; + for (i = 0; i < usegs; i++) { + gpuIndexus(base+usegs+1); + gpuIndexus(base); + + gpuIndexus(base+1); + gpuIndexus(base); + + gpuIndexus(base+usegs+2); + gpuIndexus(base); + + base++; + } + } + + base = (usegs+1) * vsegs; + + for (i = 0; i < usegs; i++) { + gpuIndexus(base+1); + gpuIndexus(base); + + base++; + } + + base = usegs; + + for (j = 0; j < vsegs; j++) { + gpuIndexus(base+usegs+1); + gpuIndexus(base); + + if (uCycle) { + gpuIndexus(base-usegs); + gpuIndexus(base); + + gpuIndexus(base+1); + gpuIndexus(base); + } + + base += usegs+1; + } + + if (uCycle) { + gpuIndexus(base-usegs); + gpuIndexus(base); + } + + break; + + case GPU_DRAW_STYLE_POINTS: + /* making an index would be wasteful */ + break; + + default: + break; + } + + gpuIndexEnd(); +} + + + +void gpuAppendCone( + GPUprim3* prim, + GLfloat radiusBase, + GLfloat height) +{ + copy_v3_flflfl(prim->params.sweep.point1, radiusBase, 0, 0); + copy_v3_flflfl(prim->params.sweep.point2, 0, 0, height); + + shape3(prim, sweep, NULL, 0, height, GL_TRUE); +} + + + +void gpuDrawCone( + GPUprim3* prim, + GLfloat radiusBase, + GLfloat height) +{ + gpuBegin(GL_NOOP); + gpuAppendCone(prim, radiusBase, height); + gpuEnd(); + + primDraw(prim); +} + + + +void gpuSingleCone( + GPUprim3* prim, + GLfloat radiusBase, + GLfloat height) +{ + primFormat(prim); + gpuDrawCone(prim, radiusBase, height); + gpuImmediateUnformat(); +} + + + +void gpuAppendCylinder( + GPUprim3* prim, + GLfloat radiusBase, + GLfloat radiusTop, + GLfloat height) +{ + copy_v3_flflfl(prim->params.sweep.point1, radiusBase, 0, 0); + copy_v3_flflfl(prim->params.sweep.point2, radiusTop, 0, height); + + shape3(prim, sweep, NULL, 0, height, GL_TRUE); +} + + + +void gpuDrawCylinder( + GPUprim3* prim, + GLfloat radiusBase, + GLfloat radiusTop, + GLfloat height) +{ + gpuBegin(GL_NOOP); + gpuAppendCylinder(prim, radiusBase, radiusTop, height); + gpuEnd(); + + primDraw(prim); +} + + + +void gpuSingleCylinder( + GPUprim3* prim, + GLfloat radiusBase, + GLfloat radiusTop, + GLfloat height) +{ + primFormat(prim); + gpuDrawCylinder(prim, radiusBase, radiusTop, height); + gpuImmediateUnformat(); +} + + + +void gpuAppendSphere( + GPUprim3* prim, + GLfloat radius) +{ + prim->params.sphere.radius = radius; + prim->params.sphere.zMin = -radius; + prim->params.sphere.zMax = radius; + + shape3( + prim, + sphere, + sphereNormals, + prim->params.sphere.zMin, + prim->params.sphere.zMax, + GL_FALSE); +} + + + +void gpuDrawSphere( + GPUprim3* prim, + GLfloat radius) +{ + gpuBegin(GL_NOOP); + gpuAppendSphere(prim, radius); + gpuEnd(); + + primDraw(prim); +} + + + +void gpuSingleSphere( + GPUprim3* prim, + GLfloat radius) +{ + primFormat(prim); + gpuDrawSphere(prim, radius); + gpuImmediateUnformat(); +} + + + +const GPUprim3 GPU_PRIM_LOFI_SOLID = { + GPU_LOD_LO, /* GLfloat usegs; */ + GPU_LOD_LO/2.0f, /* GLfloat vsegs; */ + GPU_NORMALS_SMOOTH, /* GLenum normals; */ + GPU_DRAW_STYLE_FILL, /* GLenum drawStyle; */ + GL_FALSE, /* GLboolean flipNormals */ + GL_FALSE, /* GLboolean texCoords */ + 0, /* GLfloat thetaMin */ + (float)(2*M_PI), /* GLfloat thetaMax */ +}; + +const GPUprim3 GPU_PRIM_LOFI_SHADELESS = { + GPU_LOD_LO, /* GLfloat usegs; */ + GPU_LOD_LO/2.0f, /* GLfloat vsegs; */ + GPU_NORMALS_NONE, /* GLenum normals; */ + GPU_DRAW_STYLE_FILL, /* GLenum drawStyle; */ + GL_FALSE, /* GLboolean flipNormals */ + GL_FALSE, /* GLboolean texCoords */ + 0, /* GLfloat thetaMin */ + (float)(2*M_PI), /* GLfloat thetaMax */ +}; + +const GPUprim3 GPU_PRIM_LOFI_WIRE = { + GPU_LOD_LO, /* GLfloat usegs; */ + GPU_LOD_LO/2.0f, /* GLfloat vsegs; */ + GPU_NORMALS_NONE, /* GLenum normals; */ + GPU_DRAW_STYLE_SILHOUETTE, /* GLenum drawStyle; */ + GL_FALSE, /* GLboolean flipNormals */ + GL_FALSE, /* GLboolean texCoords */ + 0, /* GLfloat thetaMin */ + (float)(2*M_PI), /* GLfloat thetaMax */ +}; + +const GPUprim3 GPU_PRIM_MIDFI_SOLID = { + GPU_LOD_MID, /* GLfloat usegs; */ + GPU_LOD_MID/2.0f, /* GLfloat vsegs; */ + GPU_NORMALS_SMOOTH, /* GLenum normals; */ + GPU_DRAW_STYLE_FILL, /* GLenum drawStyle; */ + GL_FALSE, /* GLboolean flipNormals */ + GL_FALSE, /* GLboolean texCoords */ + 0, /* GLfloat thetaMin */ + (float)(2*M_PI), /* GLfloat thetaMax */ +}; + +const GPUprim3 GPU_PRIM_MIDFI_WIRE = { + GPU_LOD_MID, /* GLfloat usegs; */ + GPU_LOD_MID/2.0f, /* GLfloat vsegs; */ + GPU_NORMALS_NONE, /* GLenum normals; */ + GPU_DRAW_STYLE_SILHOUETTE, /* GLenum drawStyle; */ + GL_FALSE, /* GLboolean flipNormals */ + GL_FALSE, /* GLboolean texCoords */ + 0, /* GLfloat thetaMin */ + (float)(2*M_PI), /* GLfloat thetaMax */ +}; + +const GPUprim3 GPU_PRIM_HIFI_SOLID = { + GPU_LOD_HI, /* GLfloat usegs; */ + GPU_LOD_HI/2.0f, /* GLfloat vsegs; */ + GPU_NORMALS_SMOOTH, /* GLenum normals; */ + GPU_DRAW_STYLE_FILL, /* GLenum drawStyle; */ + GL_FALSE, /* GLboolean flipNormals */ + GL_FALSE, /* GLboolean texCoords */ + 0, /* GLfloat thetaMin */ + (float)(2*M_PI), /* GLfloat thetaMax */ +}; + + +static float cube[8][3] = { + {-1.0, -1.0, -1.0}, + {-1.0, -1.0, 1.0}, + {-1.0, 1.0, 1.0}, + {-1.0, 1.0, -1.0}, + { 1.0, -1.0, -1.0}, + { 1.0, -1.0, 1.0}, + { 1.0, 1.0, 1.0}, + { 1.0, 1.0, -1.0}, +}; + +void gpuSingleWireUnitCube(void) +{ + gpuImmediateFormat_V3(); + + gpuBegin(GL_LINE_STRIP); + gpuVertex3fv(cube[0]); gpuVertex3fv(cube[1]); gpuVertex3fv(cube[2]); gpuVertex3fv(cube[3]); + gpuVertex3fv(cube[0]); gpuVertex3fv(cube[4]); gpuVertex3fv(cube[5]); gpuVertex3fv(cube[6]); + gpuVertex3fv(cube[7]); gpuVertex3fv(cube[4]); + gpuEnd(); + + gpuBegin(GL_LINES); + gpuVertex3fv(cube[1]); gpuVertex3fv(cube[5]); + gpuVertex3fv(cube[2]); gpuVertex3fv(cube[6]); + gpuVertex3fv(cube[3]); gpuVertex3fv(cube[7]); + gpuEnd(); + + gpuImmediateUnformat(); +} + +/* draws a cube on given the scaling of the cube, assuming that + * all required matrices have been set (used for drawing empties) + */ +void gpuSingleWireCube(GLfloat size) +{ + gpuImmediateFormat_V3(); + + gpuBegin(GL_LINE_STRIP); + gpuVertex3f(-size, -size, -size); gpuVertex3f(-size, -size, size); + gpuVertex3f(-size, size, size); gpuVertex3f(-size, size, -size); + + gpuVertex3f(-size, -size, -size); gpuVertex3f(size, -size, -size); + gpuVertex3f(size, -size, size); gpuVertex3f(size, size, size); + + gpuVertex3f(size, size, -size); gpuVertex3f(size, -size, -size); + gpuEnd(); + + gpuBegin(GL_LINES); + gpuVertex3f(-size, -size, size); gpuVertex3f(size, -size, size); + gpuVertex3f(-size, size, size); gpuVertex3f(size, size, size); + gpuVertex3f(-size, size, -size); gpuVertex3f(size, size, -size); + gpuEnd(); + + gpuImmediateUnformat(); +} + +/* half the cube, in Y */ +static float half_cube[8][3] = { + {-1.0, 0.0, -1.0}, + {-1.0, 0.0, 1.0}, + {-1.0, 1.0, 1.0}, + {-1.0, 1.0, -1.0}, + { 1.0, 0.0, -1.0}, + { 1.0, 0.0, 1.0}, + { 1.0, 1.0, 1.0}, + { 1.0, 1.0, -1.0}, +}; + +void gpuDrawSolidHalfCube(void) +{ + float n[3] = {0,0,0}; + + gpuBegin(GL_QUADS); + n[0] = -1.0; + gpuNormal3fv(n); + gpuVertex3fv(half_cube[0]); gpuVertex3fv(half_cube[1]); gpuVertex3fv(half_cube[2]); gpuVertex3fv(half_cube[3]); + n[0] = 0; + n[1] = -1.0; + gpuNormal3fv(n); + gpuVertex3fv(half_cube[0]); gpuVertex3fv(half_cube[4]); gpuVertex3fv(half_cube[5]); gpuVertex3fv(half_cube[1]); + n[1] = 0; + n[0] = 1.0; + gpuNormal3fv(n); + gpuVertex3fv(half_cube[4]); gpuVertex3fv(half_cube[7]); gpuVertex3fv(half_cube[6]); gpuVertex3fv(half_cube[5]); + n[0] = 0; + n[1] = 1.0; + gpuNormal3fv(n); + gpuVertex3fv(half_cube[7]); gpuVertex3fv(half_cube[3]); gpuVertex3fv(half_cube[2]); gpuVertex3fv(half_cube[6]); + n[1] = 0; + n[2] = 1.0; + gpuNormal3fv(n); + gpuVertex3fv(half_cube[1]); gpuVertex3fv(half_cube[5]); gpuVertex3fv(half_cube[6]); gpuVertex3fv(half_cube[2]); + n[2] = -1.0; + gpuNormal3fv(n); + gpuVertex3fv(half_cube[7]); gpuVertex3fv(half_cube[4]); gpuVertex3fv(half_cube[0]); gpuVertex3fv(half_cube[3]); + gpuEnd(); +} + +void gpuDrawWireHalfCube(void) +{ + gpuBegin(GL_LINE_STRIP); + gpuVertex3fv(half_cube[0]); gpuVertex3fv(half_cube[1]); gpuVertex3fv(half_cube[2]); gpuVertex3fv(half_cube[3]); + gpuVertex3fv(half_cube[0]); gpuVertex3fv(half_cube[4]); gpuVertex3fv(half_cube[5]); gpuVertex3fv(half_cube[6]); + gpuVertex3fv(half_cube[7]); gpuVertex3fv(half_cube[4]); + gpuEnd(); + + gpuBegin(GL_LINES); + gpuVertex3fv(half_cube[1]); gpuVertex3fv(half_cube[5]); + gpuVertex3fv(half_cube[2]); gpuVertex3fv(half_cube[6]); + gpuVertex3fv(half_cube[3]); gpuVertex3fv(half_cube[7]); + gpuEnd(); +} diff --git a/source/blender/gpu/intern/gpu_primitives_inline.h b/source/blender/gpu/intern/gpu_primitives_inline.h new file mode 100644 index 00000000000..db0624faffd --- /dev/null +++ b/source/blender/gpu/intern/gpu_primitives_inline.h @@ -0,0 +1,244 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file GPU_primitives.h + * \ingroup gpu + */ + +#ifndef __GPU_PRIMITIVES_INLINE_H__ +#define __GPU_PRIMITIVES_INLINE_H__ + + + +#include "GPU_immediate.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + +BLI_INLINE void gpuAppendLinef(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + gpuVertex2f(x1, y1); + gpuVertex2f(x2, y2); +} + +BLI_INLINE void gpuAppendLinei(GLint x1, GLint y1, GLint x2, GLint y2) +{ + gpuVertex2i(x1, y1); + gpuVertex2i(x2, y2); +} + +BLI_INLINE void gpuDrawLinef(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + gpuBegin(GL_LINES); + gpuAppendLinef(x1, y1, x2, y2); + gpuEnd(); +} + +BLI_INLINE void gpuDrawLinei(GLint x1, GLint y1, GLint x2, GLint y2) +{ + gpuBegin(GL_LINES); + gpuAppendLinei(x1, y1, x2, y2); + gpuEnd(); +} + + + +BLI_INLINE void gpuAppendFilledRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + gpuVertex2f(x1, y1); + gpuVertex2f(x2, y1); + gpuVertex2f(x2, y2); + + gpuVertex2f(x1, y1); + gpuVertex2f(x2, y2); + gpuVertex2f(x1, y2); +} + +BLI_INLINE void gpuAppendFilledRecti(GLint x1, GLint y1, GLint x2, GLint y2) +{ + gpuVertex2i(x1, y1); + gpuVertex2i(x2, y1); + gpuVertex2i(x2, y2); + + gpuVertex2i(x1, y1); + gpuVertex2i(x2, y2); + gpuVertex2i(x1, y2); +} + +BLI_INLINE void gpuAppendWireRectf( + GLfloat x1, + GLfloat y1, + GLfloat x2, + GLfloat y2) +{ + gpuVertex2f(x1, y1); + gpuVertex2f(x2, y1); + gpuVertex2f(x2, y2); + gpuVertex2f(x1, y2); +} + +BLI_INLINE void gpuAppendWireRecti( + GLint x1, + GLint y1, + GLint x2, + GLint y2) +{ + gpuVertex2i(x1, y1); + gpuVertex2i(x2, y1); + gpuVertex2i(x2, y2); + gpuVertex2i(x1, y2); +} + +BLI_INLINE void gpuDrawFilledRectf( + GLfloat x1, + GLfloat y1, + GLfloat x2, + GLfloat y2) +{ + gpuBegin(GL_TRIANGLES); + gpuAppendFilledRectf(x1, y1, x2, y2); + gpuEnd(); +} + +BLI_INLINE void gpuDrawFilledRecti( + GLint x1, + GLint y1, + GLint x2, + GLint y2) +{ + gpuBegin(GL_TRIANGLES); + gpuAppendFilledRecti(x1, y1, x2, y2); + gpuEnd(); +} + +BLI_INLINE void gpuDrawWireRectf( + GLfloat x1, + GLfloat y1, + GLfloat x2, + GLfloat y2) +{ + gpuBegin(GL_LINE_LOOP); + gpuAppendWireRectf(x1, y1, x2, y2); + gpuEnd(); +} + +BLI_INLINE void gpuDrawWireRecti( + GLint x1, + GLint y1, + GLint x2, + GLint y2) +{ + gpuBegin(GL_LINE_LOOP); + gpuAppendWireRecti(x1, y1, x2, y2); + gpuEnd(); +} + + + +BLI_INLINE void gpuAppendEllipse( + GLfloat x, + GLfloat y, + GLfloat xradius, + GLfloat yradius, + GLint nsegments) +{ + gpuAppendArc(x, y, 0, (float)(2.0 * M_PI), xradius, yradius, nsegments); +} + +BLI_INLINE void gpuDrawEllipse( + GLfloat x, + GLfloat y, + GLfloat xradius, + GLfloat yradius, + GLint nsegments) +{ + gpuDrawArc(x, y, 0, (float)(2.0 * M_PI), xradius, yradius, nsegments); +} + +BLI_INLINE void gpuSingleEllipse( + GLfloat x, + GLfloat y, + GLfloat xradius, + GLfloat yradius, + GLint nsegments) +{ + gpuSingleArc(x, y, 0, (float)(2.0 * M_PI), xradius, yradius, nsegments); +} + + + +BLI_INLINE void gpuAppendCircle( + GLfloat x, + GLfloat y, + GLfloat radius, + GLint nsegments) +{ + gpuAppendEllipse(x, y, radius, radius, nsegments); +} + +BLI_INLINE void gpuDrawCircle( + GLfloat x, + GLfloat y, + GLfloat radius, + GLint nsegments) +{ + gpuDrawEllipse(x, y, radius, radius, nsegments); +} + +/** + * Draw a lined (non-looping) arc with the given + * \a radius, starting at angle \a start and arcing + * through \a angle. The arc is centered at the origin + * and drawn in the XY plane. + * + * \param start The initial angle (in radians). + * \param angle The length of the arc (in radians). + * \param radius The arc radius. + * \param nsegments The number of segments to use in drawing the arc. + */ +BLI_INLINE void gpuSingleCircle( + GLfloat x, + GLfloat y, + GLfloat radius, + GLint nsegments) +{ + gpuSingleEllipse(x, y, radius, radius, nsegments); +} + + + +#ifdef __cplusplus +} +#endif + + + +#endif /* __GPU_PRIMITIVES_INLINE_H_ */ diff --git a/source/blender/gpu/intern/gpu_profile.h b/source/blender/gpu/intern/gpu_profile.h new file mode 100644 index 00000000000..aa71b081bd9 --- /dev/null +++ b/source/blender/gpu/intern/gpu_profile.h @@ -0,0 +1,53 @@ +#ifndef _GPU_PROFILE_H_ +#define _GPU_PROFILE_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_profile.h + * \ingroup gpu + */ + +#if defined(WITH_GL_PROFILE_ES20) +#define GPU_PROFILE_ES20 1 +#else +#define GPU_PROFILE_ES20 0 +#endif + +#if defined(WITH_GL_PROFILE_CORE) +#define GPU_PROFILE_CORE 1 +#else +#define GPU_PROFILE_CORE 0 +#endif + +#if defined(WITH_GL_PROFILE_COMPAT) +#define GPU_PROFILE_COMPAT 1 +#else +#define GPU_PROFILE_COMPAT 0 +#endif + +#endif diff --git a/source/blender/gpu/intern/gpu_raster.c b/source/blender/gpu/intern/gpu_raster.c new file mode 100644 index 00000000000..cbda490f980 --- /dev/null +++ b/source/blender/gpu/intern/gpu_raster.c @@ -0,0 +1,691 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_raster.c + * \ingroup gpu + */ + +#define GPU_MANGLE_DEPRECATED 0 + +/* my interface */ +#include "intern/gpu_raster_intern.h" + +/* my library */ +#include "GPU_blender_aspect.h" +#include "GPU_extensions.h" +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_common_intern.h" +#include "intern/gpu_immediate_intern.h" +#include "intern/gpu_matrix_intern.h" + +/* external */ + +#include "BLI_dynstr.h" + +#include "DNA_userdef_types.h" + +#include "MEM_guardedalloc.h" + +/* standard */ +#include <string.h> + + + +/* patterns */ + +const GLubyte GPU_stipple_halftone[128] = { + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; + + +/* repeat this pattern + * + * X000X000 + * 00000000 + * 00X000X0 + * 00000000 */ + + +const GLubyte GPU_stipple_quarttone[128] = { + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0, + 136, 136, 136, 136, 0, 0, 0, 0, 34, 34, 34, 34, 0, 0, 0, 0 +}; + + +const GLubyte GPU_stipple_diag_stripes_pos[128] = { + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f +}; + + +const GLubyte GPU_stipple_diag_stripes_neg[128] = { + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80 +}; + + + +const GLubyte GPU_stipple_checker_8px[128] = { + 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, + 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, + 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, + 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, + 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, + 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, + 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, + 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255 +}; + + + +/* State */ + +static struct RASTER { + uint32_t options; + + struct GPUShader* gpushader[GPU_RASTER_OPTION_COMBINATIONS]; + bool failed [GPU_RASTER_OPTION_COMBINATIONS]; + struct GPUcommon common [GPU_RASTER_OPTION_COMBINATIONS]; + + GLubyte polygon_stipple[32*32]; + + GLint line_stipple_factor; + GLushort line_stipple_pattern; + + GLfloat line_width; + + GLenum polygon_mode; + +} RASTER; + +#if GPU_SAFETY +static bool RASTER_BEGUN = false; +#endif + + + +/* Init / exit */ + +void gpu_raster_init(void) +{ + memset(&RASTER, 0, sizeof(RASTER)); + + gpu_raster_reset_stipple(); + + RASTER.line_width = 1; + + RASTER.line_stipple_factor = 1; + RASTER.line_stipple_pattern = 0xFFFF; + + RASTER.polygon_mode = GL_FILL; + + GPU_CHECK_NO_ERROR(); +} + + + +void gpu_raster_exit(void) +{ + int i; + + for (i = 0; i < GPU_RASTER_OPTION_COMBINATIONS; i++) + if (RASTER.gpushader[i] != NULL) + GPU_shader_free(RASTER.gpushader[i]); +} + + + +void gpu_raster_reset_stipple(void) +{ + int a, x, y; + GLubyte mask[32*32]; + + a = 0; + for (x = 0; x<32; x++) { + for (y = 0; y<4; y++) { + if (x & 1) + mask[a++]= 0x88; + else + mask[a++]= 0x22; + } + } + + gpuPolygonStipple((GLubyte*)mask); +} + + + +/* Shader feature enable/disable */ + +void gpu_raster_enable(uint32_t options) +{ + RASTER.options |= options; +} + + + +void gpu_raster_disable(uint32_t options) +{ + RASTER.options &= ~options; +} + + + +static void raster_shader_bind(void) +{ + /* glsl code */ + extern const char datatoc_gpu_shader_raster_frag_glsl[]; + extern const char datatoc_gpu_shader_raster_vert_glsl[]; + extern const char datatoc_gpu_shader_raster_uniforms_glsl[]; + + const uint32_t tweaked_options = RASTER.options;//tweak_options(); + + /* create shader if it doesn't exist yet */ + if (RASTER.gpushader[tweaked_options] != NULL) { + GPU_shader_bind(RASTER.gpushader[tweaked_options]); + gpu_set_common(RASTER.common + tweaked_options); + } + else if (!RASTER.failed[tweaked_options]) { + DynStr* vert = BLI_dynstr_new(); + DynStr* frag = BLI_dynstr_new(); + DynStr* defs = BLI_dynstr_new(); + + char* vert_cstring; + char* frag_cstring; + char* defs_cstring; + + char nickname[20]; + + gpu_include_common_vert(vert); + BLI_dynstr_append(vert, datatoc_gpu_shader_raster_uniforms_glsl); + BLI_dynstr_append(vert, datatoc_gpu_shader_raster_vert_glsl); + + gpu_include_common_frag(frag); + BLI_dynstr_append(vert, datatoc_gpu_shader_raster_uniforms_glsl); + BLI_dynstr_append(frag, datatoc_gpu_shader_raster_frag_glsl); + + gpu_include_common_defs(defs); + + if (tweaked_options & GPU_RASTER_STIPPLE) + BLI_dynstr_append(defs, "#define USE_STIPPLE\n"); + + if (tweaked_options & GPU_RASTER_AA) + BLI_dynstr_append(defs, "#define USE_AA\n"); + + if (tweaked_options & GPU_RASTER_POLYGON) + BLI_dynstr_append(defs, "#define USE_POLYGON\n"); + + vert_cstring = BLI_dynstr_get_cstring(vert); + frag_cstring = BLI_dynstr_get_cstring(frag); + defs_cstring = BLI_dynstr_get_cstring(defs); + + sprintf(nickname, "Raster[0x%04X]", tweaked_options); + + RASTER.gpushader[tweaked_options] = + GPU_shader_create(nickname, vert_cstring, frag_cstring, NULL, defs_cstring); + + MEM_freeN(vert_cstring); + MEM_freeN(frag_cstring); + MEM_freeN(defs_cstring); + + BLI_dynstr_free(vert); + BLI_dynstr_free(frag); + BLI_dynstr_free(defs); + + if (RASTER.gpushader[tweaked_options] != NULL) { + gpu_common_get_symbols(RASTER.common + tweaked_options, RASTER.gpushader[tweaked_options]); + gpu_set_common (RASTER.common + tweaked_options); + + GPU_shader_bind(RASTER.gpushader[tweaked_options]); + } + else { + RASTER.failed[tweaked_options] = true; + gpu_set_common(NULL); + } + } + else { + gpu_set_common(NULL); + } +} + + + +void gpu_raster_bind(void) +{ + bool glsl_support = GPU_glsl_support(); + + GPU_ASSERT(RASTER_BEGUN); + + if (glsl_support) + raster_shader_bind(); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (!glsl_support) { + GPU_CHECK_NO_ERROR(); + + if (RASTER.options & GPU_RASTER_STIPPLE) { + glEnable(GL_LINE_STIPPLE); + glEnable(GL_POLYGON_STIPPLE); + } + else { + glDisable(GL_LINE_STIPPLE); + glDisable(GL_POLYGON_STIPPLE); + } + + if (RASTER.options & GPU_RASTER_AA) { + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POLYGON_SMOOTH); + } + else { + glDisable(GL_LINE_SMOOTH); + glDisable(GL_POLYGON_SMOOTH); + } + + glLineWidth(RASTER.line_width); + glLineStipple(RASTER.line_stipple_factor, RASTER.line_stipple_pattern); + + glPolygonMode(GL_FRONT_AND_BACK, RASTER.polygon_mode); + glPolygonStipple(RASTER.polygon_stipple); + + GPU_CHECK_NO_ERROR(); + } +#endif + + gpu_commit_matrix(); +} + + + +void gpu_raster_unbind(void) +{ + bool glsl_support = GPU_glsl_support(); + + GPU_ASSERT(RASTER_BEGUN); + + if (glsl_support) + GPU_shader_unbind(); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (!glsl_support) { + GPU_CHECK_NO_ERROR(); + + glDisable(GL_LINE_STIPPLE); + glDisable(GL_POLYGON_STIPPLE); + + glDisable(GL_LINE_SMOOTH); + glDisable(GL_POLYGON_SMOOTH); + + glLineWidth(1); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + GPU_CHECK_NO_ERROR(); + } +#endif +} + + + +void gpuPolygonStipple(const GLubyte* mask) +{ + memcpy(RASTER.polygon_stipple, mask, sizeof(RASTER.polygon_stipple)); +} + + + +void gpuLineStipple(GLint factor, GLushort pattern) +{ + RASTER.line_stipple_factor = factor; + RASTER.line_stipple_pattern = pattern; +} + + + +void gpuLineWidth(GLfloat width) +{ + RASTER.line_width = width; +} + + + +GLfloat gpuGetLineWidth(void) +{ + return RASTER.line_width; +} + + + +void gpuPolygonMode(GLenum mode) +{ + RASTER.polygon_mode = mode; +} + + + +GLenum gpuGetPolygonMode(void) +{ + return RASTER.polygon_mode; +} + + + +void GPU_raster_set_line_style(int factor) +{ + if (factor == 0) { + GPU_aspect_disable(GPU_ASPECT_RASTER, GPU_RASTER_STIPPLE); + } + else { + GPU_aspect_enable(GPU_ASPECT_RASTER, GPU_RASTER_STIPPLE); + + if (U.pixelsize > 1.0f) + gpuLineStipple(factor, 0xCCCC); + else + gpuLineStipple(factor, 0xAAAA); + } +} + + + +void GPU_raster_begin() +{ +#if GPU_SAFETY + GPU_ASSERT(!RASTER_BEGUN); + RASTER_BEGUN = true; +#endif + + // SSS End (Assuming the basic aspect is ending) + GPU_aspect_end(); + + // SSS Begin Raster + GPU_aspect_begin(GPU_ASPECT_RASTER, NULL); +} + + + +void GPU_raster_end() +{ +#if GPU_SAFETY + GPU_ASSERT(RASTER_BEGUN); +#endif + + // SSS End Raster + GPU_aspect_end(); + +#if GPU_SAFETY + RASTER_BEGUN = false; +#endif + + // SSS Begin Basic + GPU_aspect_begin(GPU_ASPECT_BASIC, NULL); +} + + + + +static GLboolean end_begin(void) +{ +#if GPU_SAFETY + GPU_IMMEDIATE->hasOverflowed = GL_TRUE; +#endif + + if (!ELEM( + GPU_IMMEDIATE->mode, + GL_NOOP, + GL_LINE_LOOP, + GL_POLYGON, + GL_QUAD_STRIP, + GL_LINE_STRIP, + GL_TRIANGLE_STRIP)) // XXX jwilkins: can restart some of these, but need to put in the logic (could be problematic with mapped VBOs?) + { + gpu_end_buffer_gl(); + + GPU_IMMEDIATE->mappedBuffer = NULL; + GPU_IMMEDIATE->offset = 0; + GPU_IMMEDIATE->count = 1; /* count the vertex that triggered this */ + + gpu_begin_buffer_gl(); + + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + + + +static void gpu_copy_vertex_thick_line(void) +{ + size_t i; + size_t size; + size_t offset; + GLubyte *__restrict mappedBuffer; + +#if GPU_SAFETY + { + int maxVertexCountOK; + GPU_SAFE_RETURN(GPU_IMMEDIATE->maxVertexCount != 0, maxVertexCountOK,); + } +#endif + + if (GPU_IMMEDIATE->count == GPU_IMMEDIATE->lastPrimVertex) { + GLboolean restarted; + + restarted = end_begin(); /* draw and clear buffer */ + + GPU_ASSERT(restarted); + + if (!restarted) + return; + } + else { + GPU_IMMEDIATE->count++; + } + + mappedBuffer = GPU_IMMEDIATE->mappedBuffer; + offset = GPU_IMMEDIATE->offset; + + /* vertex */ + + size = (size_t)(GPU_IMMEDIATE->format.vertexSize) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->vertex, size); + offset += size; + + /* normal */ + + if (GPU_IMMEDIATE->format.normalSize != 0) { + /* normals are always have 3 components */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->normal, 3*sizeof(GLfloat)); + offset += 3*sizeof(GLfloat); + } + + /* color */ + + if (GPU_IMMEDIATE->format.colorSize != 0) { + /* 4 bytes are always reserved for color, for efficient memory alignment */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->color, 4*sizeof(GLubyte)); + offset += 4*sizeof(GLubyte); + } + + /* texture coordinate(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.texCoordCount; i++) { + size = (size_t)(GPU_IMMEDIATE->format.texCoordSize[i]) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->texCoord[i], size); + offset += size; + } + + /* float vertex attribute(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) { + size = (size_t)(GPU_IMMEDIATE->format.attribSize_f[i]) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->attrib_f[i], size); + offset += size; + } + + /* unsigned byte vertex attribute(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) { + /* 4 bytes are always reserved for byte attributes, for efficient memory alignment */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->attrib_ub[i], 4*sizeof(GLubyte)); + offset += 4*sizeof(GLubyte); + } + + GPU_IMMEDIATE->offset = offset; +} + + + +static void gpu_copy_vertex_wire_polygon(void) +{ + size_t i; + size_t size; + size_t offset; + GLubyte *__restrict mappedBuffer; + +#if GPU_SAFETY + { + int maxVertexCountOK; + GPU_SAFE_RETURN(GPU_IMMEDIATE->maxVertexCount != 0, maxVertexCountOK,); + } +#endif + + if (GPU_IMMEDIATE->count == GPU_IMMEDIATE->lastPrimVertex) { + GLboolean restarted; + + restarted = end_begin(); /* draw and clear buffer */ + + GPU_ASSERT(restarted); + + if (!restarted) + return; + } + else { + GPU_IMMEDIATE->count++; + } + + mappedBuffer = GPU_IMMEDIATE->mappedBuffer; + offset = GPU_IMMEDIATE->offset; + + /* vertex */ + + size = (size_t)(GPU_IMMEDIATE->format.vertexSize) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->vertex, size); + offset += size; + + /* normal */ + + if (GPU_IMMEDIATE->format.normalSize != 0) { + /* normals are always have 3 components */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->normal, 3*sizeof(GLfloat)); + offset += 3*sizeof(GLfloat); + } + + /* color */ + + if (GPU_IMMEDIATE->format.colorSize != 0) { + /* 4 bytes are always reserved for color, for efficient memory alignment */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->color, 4*sizeof(GLubyte)); + offset += 4*sizeof(GLubyte); + } + + /* texture coordinate(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.texCoordCount; i++) { + size = (size_t)(GPU_IMMEDIATE->format.texCoordSize[i]) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->texCoord[i], size); + offset += size; + } + + /* float vertex attribute(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_f; i++) { + size = (size_t)(GPU_IMMEDIATE->format.attribSize_f[i]) * sizeof(GLfloat); + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->attrib_f[i], size); + offset += size; + } + + /* unsigned byte vertex attribute(s) */ + + for (i = 0; i < GPU_IMMEDIATE->format.attribCount_ub; i++) { + /* 4 bytes are always reserved for byte attributes, for efficient memory alignment */ + memcpy(mappedBuffer + offset, GPU_IMMEDIATE->attrib_ub[i], 4*sizeof(GLubyte)); + offset += 4*sizeof(GLubyte); + } + + GPU_IMMEDIATE->offset = offset; +} diff --git a/source/blender/gpu/intern/gpu_raster_intern.h b/source/blender/gpu/intern/gpu_raster_intern.h new file mode 100644 index 00000000000..664dce95d0d --- /dev/null +++ b/source/blender/gpu/intern/gpu_raster_intern.h @@ -0,0 +1,58 @@ +#ifndef _GPU_RASTER_INTERN_H_ +#define _GPU_RASTER_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_raster_intern.h + * \ingroup gpu + */ + +#include "GPU_raster.h" + +#include "BLI_sys_types.h" /* for uint32_t */ + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_raster_init(void); +void gpu_raster_exit(void); + +void gpu_raster_enable (uint32_t options); +void gpu_raster_disable(uint32_t options); + +void gpu_raster_bind (void); +void gpu_raster_unbind(void); + +void gpu_raster_reset_stipple(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_RASTER_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_safety.c b/source/blender/gpu/intern/gpu_safety.c new file mode 100644 index 00000000000..998f52d501a --- /dev/null +++ b/source/blender/gpu/intern/gpu_safety.c @@ -0,0 +1,76 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_safety.c + * \ingroup gpu + */ + +/* my interface */ +#include "GPU_safety.h" + +#if GPU_SAFETY + +#include "GPU_utility.h" + +#include <stdio.h> + + + +void gpu_check(const char* file, int line, const char* text) +{ + GLboolean no_gl_error = GL_TRUE; + GLenum last_gl_error = GL_NO_ERROR; + + for (;;) { + GLenum gl_error = glGetError(); + + if (gl_error == GL_NO_ERROR) { + break; + } + else { + /* glGetError should have cleared the error flag, so if we get the + same flag twice that means glGetError itself probably triggered + the error. This happens on Windows if the GL context is invalid. + */ + BLI_assert(gl_error != last_gl_error); + + no_gl_error = GL_FALSE; + + if (text == NULL) + fprintf(stderr, "%s(%d): GL Error (0x%04X - %s): %s\n", file, line, gl_error, gpuErrorSymbol(gl_error), gpuErrorString(gl_error)); + else + fprintf(stderr, "%s(%d):[%s] -> GL Error (0x%04X - %s): %s\n", file, line, text, gl_error, gpuErrorSymbol(gl_error), gpuErrorString(gl_error)); + + last_gl_error = gl_error; + } + } + + if (!no_gl_error) + abort(); +} + +#endif diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c index 2df9e603903..17fd584a340 100644 --- a/source/blender/gpu/intern/gpu_select.c +++ b/source/blender/gpu/intern/gpu_select.c @@ -18,7 +18,7 @@ * The Original Code is Copyright (C) 2014 Blender Foundation. * All rights reserved. * - * Contributor(s): Antony Riakiotakis. + * Contributor(s): Antony Riakiotakis, Jason Wilkins. * * ***** END GPL LICENSE BLOCK ***** */ @@ -29,6 +29,11 @@ * Interface for accessing gpu-related methods for selection. The semantics will be * similar to glRenderMode(GL_SELECT) since the goal is to maintain compatibility. */ + +#if WITH_GL_PROFILE_COMPAT +#define GPU_MANGLE_DEPRECATED 0 /* Allow use of deprecated OpenGL functions in this file */ +#endif + #include "GPU_select.h" #include "GPU_extensions.h" diff --git a/source/blender/gpu/intern/gpu_select_intern.h b/source/blender/gpu/intern/gpu_select_intern.h new file mode 100644 index 00000000000..dc17436cbef --- /dev/null +++ b/source/blender/gpu/intern/gpu_select_intern.h @@ -0,0 +1,61 @@ +#ifndef _GPU_SELECT_INTERN_H_ +#define _GPU_SELECT_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_select_intern.h + * \ingroup gpu + */ + +#include "GPU_select.h" + +#include "BLI_sys_types.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + + +void gpu_select_init(void); +void gpu_select_exit(void); + +bool gpu_default_select_begin (const void* object, void* param); +bool gpu_default_select_end (const void* object, void* param); +bool gpu_default_select_commit(const void* object); + +bool gpu_is_select_mode(void); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_SELECT_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_simple_shader.c b/source/blender/gpu/intern/gpu_simple_shader.c deleted file mode 100644 index 0cb712d220f..00000000000 --- a/source/blender/gpu/intern/gpu_simple_shader.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2013 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Brecht Van Lommel. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/gpu/intern/gpu_simple_shader.c - * \ingroup gpu - * - * GLSL shaders to replace fixed function OpenGL materials and lighting. These - * are deprecated in newer OpenGL versions and missing in OpenGL ES 2.0. Also, - * two sided lighting is no longer natively supported on NVidia cards which - * results in slow software fallback. - * - * Todo: - * - Replace glLight and glMaterial functions entirely with GLSL uniforms, to - * make OpenGL ES 2.0 work. - * - Replace glTexCoord and glColor with generic attributes. - * - Optimize for case where fewer than 3 or 8 lights are used. - * - Optimize for case where specular is not used. - * - Optimize for case where no texture matrix is used. - */ - -#include "GL/glew.h" - -#include "BLI_math.h" -#include "BLI_utildefines.h" - -#include "DNA_mesh_types.h" -#include "DNA_object_types.h" - -#include "GPU_extensions.h" -#include "GPU_simple_shader.h" - -/* State */ - -// #define NUM_OPENGL_LIGHTS 8 - -static struct { - GPUShader *cached_shaders[GPU_SHADER_OPTION_COMBINATIONS]; - bool failed_shaders[GPU_SHADER_OPTION_COMBINATIONS]; - - bool need_normals; - - int lights_enabled; - int lights_directional; -} GPU_MATERIAL_STATE; - -/* Init / exit */ - -void GPU_simple_shaders_init(void) -{ - memset(&GPU_MATERIAL_STATE, 0, sizeof(GPU_MATERIAL_STATE)); -} - -void GPU_simple_shaders_exit(void) -{ - int i; - - for (i = 0; i < GPU_SHADER_OPTION_COMBINATIONS; i++) - if (GPU_MATERIAL_STATE.cached_shaders[i]) - GPU_shader_free(GPU_MATERIAL_STATE.cached_shaders[i]); -} - -/* Shader lookup / create */ - -static bool solid_compatible_lighting(void) -{ - int enabled = GPU_MATERIAL_STATE.lights_enabled; - int directional = GPU_MATERIAL_STATE.lights_directional; - - /* more than 3 lights? */ - if (enabled >= (1 << 3)) - return false; - - /* all directional? */ - return ((directional & enabled) == enabled); -} - -#if 0 -static int detect_options() -{ - GLint two_sided; - int options = 0; - - if (glIsEnabled(GL_TEXTURE_2D)) - options |= GPU_SHADER_TEXTURE_2D; - if (glIsEnabled(GL_COLOR_MATERIAL)) - options |= GPU_SHADER_OVERRIDE_DIFFUSE; - - if (glIsEnabled(GL_LIGHTING)) - options |= GPU_SHADER_LIGHTING; - - glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &two_sided); - if (two_sided == GL_TRUE) - options |= GPU_SHADER_TWO_SIDED; - - return options; -} -#endif - -static GPUShader *gpu_simple_shader(int options) -{ - /* glsl code */ - extern char datatoc_gpu_shader_simple_vert_glsl[]; - extern char datatoc_gpu_shader_simple_frag_glsl[]; - GPUShader *shader; - - /* detect if we can do faster lighting for solid draw mode */ - if (options & GPU_SHADER_LIGHTING) - if (solid_compatible_lighting()) - options |= GPU_SHADER_SOLID_LIGHTING; - - /* cached shaders */ - shader = GPU_MATERIAL_STATE.cached_shaders[options]; - - if (!shader && !GPU_MATERIAL_STATE.failed_shaders[options]) { - /* create shader if it doesn't exist yet */ - char defines[64*GPU_SHADER_OPTIONS_NUM] = ""; - - if (options & GPU_SHADER_OVERRIDE_DIFFUSE) - strcat(defines, "#define USE_COLOR\n"); - if (options & GPU_SHADER_TWO_SIDED) - strcat(defines, "#define USE_TWO_SIDED\n"); - if (options & GPU_SHADER_TEXTURE_2D) - strcat(defines, "#define USE_TEXTURE\n"); - - if (options & GPU_SHADER_SOLID_LIGHTING) - strcat(defines, "#define USE_SOLID_LIGHTING\n"); - else if (options & GPU_SHADER_LIGHTING) - strcat(defines, "#define USE_SCENE_LIGHTING\n"); - - shader = GPU_shader_create( - datatoc_gpu_shader_simple_vert_glsl, - datatoc_gpu_shader_simple_frag_glsl, - NULL, defines); - - if (shader) { - /* set texture map to first texture unit */ - if (options & GPU_SHADER_TEXTURE_2D) - glUniform1i(GPU_shader_get_uniform(shader, "texture_map"), 0); - - GPU_MATERIAL_STATE.cached_shaders[options] = shader; - } - else - GPU_MATERIAL_STATE.failed_shaders[options] = true; - } - - return shader; -} - -/* Bind / unbind */ - -void GPU_simple_shader_bind(int options) -{ - if (GPU_glsl_support()) { - GPUShader *shader = gpu_simple_shader(options); - - if (shader) - GPU_shader_bind(shader); - } - else { - // XXX where does this fit, depends on ortho/persp? - - if (options & GPU_SHADER_LIGHTING) - glEnable(GL_LIGHTING); - - if (options & GPU_SHADER_TWO_SIDED) - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - - if (options & GPU_SHADER_OVERRIDE_DIFFUSE) { - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - } - - if (options & GPU_SHADER_TEXTURE_2D) - glEnable(GL_TEXTURE_2D); - } - - /* temporary hack, should be solved outside of this file */ - GPU_MATERIAL_STATE.need_normals = (options & GPU_SHADER_LIGHTING); -} - -void GPU_simple_shader_unbind(void) -{ - if (GPU_glsl_support()) { - GPU_shader_unbind(); - } - else { - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_TEXTURE_2D); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - } -} - -/* Material Colors */ - -void GPU_simple_shader_colors(const float diffuse[3], const float specular[3], - int shininess, float alpha) -{ - float gl_diffuse[4], gl_specular[4]; - - copy_v3_v3(gl_diffuse, diffuse); - gl_diffuse[3] = alpha; - - copy_v3_v3(gl_specular, specular); - gl_specular[3] = 1.0f; - - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, gl_diffuse); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, gl_specular); - glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(shininess, 1, 128)); -} - -bool GPU_simple_shader_need_normals(void) -{ - return GPU_MATERIAL_STATE.need_normals; -} - -void GPU_simple_shader_light_set(int light_num, GPULightData *light) -{ - int light_bit = (1 << light_num); - - GPU_MATERIAL_STATE.lights_enabled &= ~light_bit; - GPU_MATERIAL_STATE.lights_directional &= ~light_bit; - - if (light) { - glEnable(GL_LIGHT0+light_num); - - glLightfv(GL_LIGHT0+light_num, GL_POSITION, light->position); - glLightfv(GL_LIGHT0+light_num, GL_DIFFUSE, light->diffuse); - glLightfv(GL_LIGHT0+light_num, GL_SPECULAR, light->specular); - - glLightf(GL_LIGHT0+light_num, GL_CONSTANT_ATTENUATION, light->constant_attenuation); - glLightf(GL_LIGHT0+light_num, GL_LINEAR_ATTENUATION, light->linear_attenuation); - glLightf(GL_LIGHT0+light_num, GL_QUADRATIC_ATTENUATION, light->quadratic_attenuation); - - glLightfv(GL_LIGHT0+light_num, GL_SPOT_DIRECTION, light->spot_direction); - glLightf(GL_LIGHT0+light_num, GL_SPOT_CUTOFF, light->spot_cutoff); - glLightf(GL_LIGHT0+light_num, GL_SPOT_EXPONENT, light->spot_exponent); - - GPU_MATERIAL_STATE.lights_enabled |= light_bit; - if (light->position[3] == 0.0f) - GPU_MATERIAL_STATE.lights_directional |= light_bit; - } - else { - const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - - glLightfv(GL_LIGHT0+light_num, GL_POSITION, zero); - glLightfv(GL_LIGHT0+light_num, GL_DIFFUSE, zero); - glLightfv(GL_LIGHT0+light_num, GL_SPECULAR, zero); - - glDisable(GL_LIGHT0+light_num); - } -} - -void GPU_simple_shader_light_set_viewer(bool local) -{ - glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (local)? GL_TRUE: GL_FALSE); -} - diff --git a/source/blender/gpu/intern/gpu_sprite.c b/source/blender/gpu/intern/gpu_sprite.c new file mode 100644 index 00000000000..8d24832d6cc --- /dev/null +++ b/source/blender/gpu/intern/gpu_sprite.c @@ -0,0 +1,350 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file source/blender/gpu/intern/gpu_sprite.c + * \ingroup gpu + */ + +#define GPU_MANGLE_DEPRECATED 0 + +/* my interface */ +#include "intern/gpu_sprite_intern.h" + +/* my library */ +#include "GPU_aspect.h" +#include "GPU_blender_aspect.h" +#include "GPU_immediate.h" +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_matrix_intern.h" +#include "intern/gpu_profile.h" + + +static float point_size = 1; + +static float SPRITE_SIZE = 1; +static uint32_t SPRITE_OPTIONS = 0; + +#if GPU_SAFETY +static bool SPRITE_BEGUN = false; +#endif + +#if defined(WITH_GL_PROFILE_COMPAT) + +static int pointhack = 0; + +static GLubyte square_dot[16] = { + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff +}; + +#endif + + + +void gpu_sprite_init(void) +{ +#if defined(WITH_GL_PROFILE_COMPAT) || defined(WITH_GL_PROFILE_CORE) + glGetFloatv(GL_POINT_SIZE, &point_size); +#else + point_size = 1; +#endif + + SPRITE_SIZE = 1; + SPRITE_OPTIONS = 0; +} + + + +void gpu_sprite_exit(void) +{ +#if GPU_SAFETY + SPRITE_BEGUN = false; +#endif +} + + + +void gpu_sprite_enable(uint32_t options) +{ + SPRITE_OPTIONS |= options; +} + + + +void gpu_sprite_disable(uint32_t options) +{ + SPRITE_OPTIONS &= ~options; +} + + + +void gpu_sprite_bind(void) +{ + GPU_ASSERT(SPRITE_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) + return; + + GPU_CHECK_NO_ERROR(); + + if (SPRITE_SIZE != point_size) + glPointSize(SPRITE_SIZE); + + if (SPRITE_OPTIONS & GPU_SPRITE_CIRCULAR) + glEnable(GL_POINT_SMOOTH); + + if (SPRITE_OPTIONS & GPU_SPRITE_TEXTURE_2D) + glEnable(GL_POINT_SPRITE); + + GPU_CHECK_NO_ERROR(); +#endif + + gpu_commit_matrix(); +} + + + +void gpu_sprite_unbind(void) +{ + GPU_ASSERT(SPRITE_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) + return; + + GPU_CHECK_NO_ERROR(); + + glPointSize(point_size); + glDisable(GL_POINT_SMOOTH); + glDisable(GL_POINT_SPRITE); + + GPU_CHECK_NO_ERROR(); +#endif +} + + + +void GPU_point_size(float size) +{ + point_size = size; + glPointSize(point_size); +} + + + +void GPU_sprite_size(float size) +{ + SPRITE_SIZE = size; +} + + + +void GPU_sprite_begin(void) +{ +#if GPU_SAFETY + GPU_ASSERT(!SPRITE_BEGUN); + SPRITE_BEGUN = true; +#endif + + GPU_aspect_end(); /* assuming was GPU_ASPECT_BASIC */ + + GPU_aspect_begin(GPU_ASPECT_SPRITE, NULL); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (GPU_PROFILE_COMPAT) { + GLfloat range[4]; + + GPU_CHECK_NO_ERROR(); + + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, range); + + if (range[1] < 2.0f) { + GLfloat size[4]; + glGetFloatv(GL_POINT_SIZE, size); + + pointhack = floor(size[0] + 0.5f); // XXX jwilkins: roundf?? + + if (pointhack > 4) { //-V112 + pointhack = 4; //-V112 + } + } + + GPU_CHECK_NO_ERROR(); + } + else +#endif + { + gpuBegin(GL_POINTS); + } +} + + + +void GPU_sprite_3fv(const float vec[3]) +{ + GPU_ASSERT(SPRITE_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) { + GPU_CHECK_NO_ERROR(); + + glRasterPos3fv(vec); + glBitmap( + pointhack, + pointhack, + pointhack / 2.0f, pointhack / 2.0f, + 0, + 0, + square_dot); + + GPU_CHECK_NO_ERROR(); + } + else +#endif + { + gpuVertex3fv(vec); + } +} + + + +void GPU_sprite_3f(float x, float y, float z) +{ + GPU_ASSERT(SPRITE_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) { + GPU_CHECK_NO_ERROR(); + + glRasterPos3f(x, y, z); + glBitmap( + pointhack, + pointhack, + pointhack / 2.0f, + pointhack / 2.0f, + 0, + 0, + square_dot); + + GPU_CHECK_NO_ERROR(); + } + else +#endif + { + gpuVertex3f(x, y, z); + } +} + + + +void GPU_sprite_2f(float x, float y) +{ + GPU_ASSERT(SPRITE_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) { + GPU_CHECK_NO_ERROR(); + + glRasterPos2f(x, y); + glBitmap( + pointhack, + pointhack, + pointhack / 2.0f, + pointhack / 2.0f, + 0, + 0, + square_dot); + + GPU_CHECK_NO_ERROR(); + } + else +#endif + { + gpuVertex2f(x, y); + } +} + + + +void GPU_sprite_2fv(const float v[2]) +{ + GPU_ASSERT(SPRITE_BEGUN); + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) { + GPU_CHECK_NO_ERROR(); + + glRasterPos2fv(v); + glBitmap( + pointhack, + pointhack, + pointhack / 2.0f, + pointhack / 2.0f, + 0, + 0, + square_dot); + + GPU_CHECK_NO_ERROR(); + } + else +#endif + { + gpuVertex2fv(v); + } +} + + + +void GPU_sprite_end(void) +{ +#if GPU_SAFETY + GPU_ASSERT(SPRITE_BEGUN); +#endif + +#if defined(WITH_GL_PROFILE_COMPAT) + if (pointhack) { + pointhack = 0; + } + else +#endif + { + gpuEnd(); + } + + GPU_aspect_end(); + +#if GPU_SAFETY + SPRITE_BEGUN = false; +#endif + + GPU_aspect_begin(GPU_ASPECT_BASIC, NULL); +} diff --git a/source/blender/gpu/intern/gpu_sprite_intern.h b/source/blender/gpu/intern/gpu_sprite_intern.h new file mode 100644 index 00000000000..a0bba395857 --- /dev/null +++ b/source/blender/gpu/intern/gpu_sprite_intern.h @@ -0,0 +1,56 @@ +#ifndef _GPU_SPRITE_INTERN_H_ +#define _GPU_SPRITE_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_sprite_intern.h + * \ingroup gpu + */ + +#include "GPU_sprite.h" + +#include "BLI_sys_types.h" // for uint32_t + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_sprite_init(void); +void gpu_sprite_exit(void); + +void gpu_sprite_enable (uint32_t options); +void gpu_sprite_disable(uint32_t options); + +void gpu_sprite_bind (void); +void gpu_sprite_unbind(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_SPRITE_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_state_latch.c b/source/blender/gpu/intern/gpu_state_latch.c new file mode 100644 index 00000000000..3ad8fc5a138 --- /dev/null +++ b/source/blender/gpu/intern/gpu_state_latch.c @@ -0,0 +1,235 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_state_latch.c + * \ingroup gpu + */ + +#define GPU_MANGLE_DEPRECATED 0 + +/* my interface */ +#include "intern/gpu_state_latch_intern.h" + +/* my library */ +#include "gpu_profile.h" +#include "GPU_safety.h" + +/* internal */ +#include "intern/gpu_profile.h" + +/* external */ +#include "BLI_sys_types.h" +#include "BLI_utildefines.h" + +/* standard */ +#include <string.h> + + + +// XXX jwilkins: this needs to be made to save these values from different contexts + +static bool depth_range_valid = false; +static GLdouble depth_range[2]; + +static bool viewport_valid = false; +static GLint viewport[4]; + +static bool texture_binding_2D_valid = false; +static GLuint texture_binding_2D; + +static bool depth_writemask_valid = false; +static GLboolean depth_writemask; + + + +void gpu_state_latch_init(void) +{ +#if defined(WITH_GL_PROFILE_COMPAT) + GLint value; + + glGetDoublev(GL_DEPTH_RANGE, depth_range); + depth_range_valid = true; + + glGetIntegerv(GL_VIEWPORT, viewport); + viewport_valid = true; + + value = 0; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &value); + texture_binding_2D = (GLuint)value; + texture_binding_2D_valid = true; + + glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_writemask); + depth_writemask_valid = true; +#else + depth_range_valid = false; + viewport_valid = false; + texture_binding_2D_valid = false; + depth_writemask_valid = false; +#endif +} + + + +void gpu_state_latch_exit(void) +{ +} + + + +void gpuDepthRange(GLdouble near, GLdouble far) +{ + GPU_ASSERT(near != far); + + VEC2D(depth_range, near, far); + + depth_range_valid = true; + +#if !defined(GLEW_ES_ONLY) + if (!GPU_PROFILE_ES20) { + GPU_CHECK(glDepthRange(near, far)); + return; + } +#endif + +#if !defined(GLEW_NO_ES) + if (GPU_PROFILE_ES20) { + GPU_CHECK(glDepthRangef((GLfloat)near, (GLfloat)far)); + return; + } +#endif +} + + + +void gpuGetDepthRange(GLdouble out[2]) +{ + GPU_ASSERT(depth_range_valid); + + VECCOPY2D(out, depth_range); +} + + + +GLfloat GPU_feedback_depth_range(GLfloat z) +{ + GLfloat depth; + + GPU_ASSERT(depth_range_valid); + + depth = depth_range[1] - depth_range[0]; + + if (depth != 0) { + return z / depth; + } + else { + GPU_ABORT(); + return z; + } +} + + + +void gpuBindTexture(GLenum target, GLuint name) +{ + switch(target) + { + case GL_TEXTURE_2D: + texture_binding_2D = name; + texture_binding_2D_valid = true; + break; + + default: + /* a target we don't care to latch */ + break; + } + + GPU_CHECK(glBindTexture(target, name)); +} + + + +GLuint gpuGetTextureBinding2D(void) +{ + GPU_ASSERT(texture_binding_2D_valid); + + return texture_binding_2D; +} + + + +void gpuDepthMask(GLboolean flag) +{ + depth_writemask = flag; + depth_writemask_valid = true; + + GPU_CHECK(glDepthMask(flag)); +} + + + +GLboolean gpuGetDepthWriteMask(void) +{ + GPU_ASSERT(depth_writemask_valid); + + return depth_writemask; +} + + + +void gpuViewport(int x, int y, int width, int height) +{ + viewport[0] = x; + viewport[1] = y; + viewport[2] = width; + viewport[3] = height; + + viewport_valid = true; + + GPU_CHECK(glViewport(x, y, width, height)); +} + + + +void gpuGetViewport(int out[4]) +{ + GPU_ASSERT(viewport_valid); + + VECCOPY4D(out, viewport); +} + + + +void GPU_feedback_viewport_2fv(GLfloat x, GLfloat y, GLfloat out[2]) +{ + const GLfloat halfw = (GLfloat)viewport[2] / 2.0f; + const GLfloat halfh = (GLfloat)viewport[3] / 2.0f; + + GPU_ASSERT(viewport_valid); + + out[0] = halfw*x + halfw + (GLfloat)viewport[0]; + out[1] = halfh*y + halfh + (GLfloat)viewport[1]; +} diff --git a/source/blender/gpu/intern/gpu_state_latch_intern.h b/source/blender/gpu/intern/gpu_state_latch_intern.h new file mode 100644 index 00000000000..32ef45c7344 --- /dev/null +++ b/source/blender/gpu/intern/gpu_state_latch_intern.h @@ -0,0 +1,48 @@ +#ifndef _GPU_STATE_LATCH_INTERN_H_ +#define _GPU_STATE_LATCH_INTERN_H_ + +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_state_latch_intern.h + * \ingroup gpu + */ + +#include "GPU_state_latch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_state_latch_init(void); +void gpu_state_latch_exit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _GPU_STATE_LATCH_INTERN_H_ */ diff --git a/source/blender/gpu/intern/gpu_utility.c b/source/blender/gpu/intern/gpu_utility.c new file mode 100644 index 00000000000..285701af1aa --- /dev/null +++ b/source/blender/gpu/intern/gpu_utility.c @@ -0,0 +1,124 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Jason Wilkins. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/gpu/intern/gpu_utility.c + * \ingroup gpu + */ + +#include "GPU_utility.h" + + + +const char* gpuErrorString(GLenum err) +{ + switch(err) { + case GL_NO_ERROR: + return "No Error"; + + case GL_INVALID_ENUM: + return "Invalid Enumeration"; + + case GL_INVALID_VALUE: + return "Invalid Value"; + + case GL_INVALID_OPERATION: + return "Invalid Operation"; + + case GL_STACK_OVERFLOW: + return "Stack Overflow"; + + case GL_STACK_UNDERFLOW: + return "Stack Underflow"; + + case GL_OUT_OF_MEMORY: + return "Out of Memory"; + +#ifdef GL_ARB_imagining + case GL_TABLE_TOO_LARGE: + return "Table Too Large"; +#endif + +#if defined(WITH_GLU) + case GLU_INVALID_ENUM: + return "Invalid Enum (GLU)"; + + case GLU_INVALID_VALUE: + return "Invalid Value (GLU)"; + + case GLU_OUT_OF_MEMORY: + return "Out of Memory (GLU)"; +#endif + + default: + return "<unknown error>"; + } +} + +const char* gpuErrorSymbol(GLenum err) +{ + switch(err) { + case GL_NO_ERROR: + return "GL_NO_ERROR"; + + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM"; + + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE"; + + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION"; + + case GL_STACK_OVERFLOW: + return "GL_STACK_OVERFLOW"; + + case GL_STACK_UNDERFLOW: + return "GL_STACK_UNDERFLOW"; + + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY"; + +#ifdef GL_ARB_imagining + case GL_TABLE_TOO_LARGE: + return "GL_TABLE_TOO_LARGE"; +#endif + +#if defined(WITH_GLU) + case GLU_INVALID_ENUM: + return "GLU_INVALID_ENUM"; + + case GLU_INVALID_VALUE: + return "GLU_INVALID_VALUE"; + + case GLU_OUT_OF_MEMORY: + return "GLU_OUT_OF_MEMORY"; +#endif + + default: + return "<unknown error>"; + } +} diff --git a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl new file mode 100644 index 00000000000..58db8eb0428 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl @@ -0,0 +1,181 @@ +/* Options: + + USE_LIGHTING + USE_FAST_LIGHTING + USE_TWO_SIDE + USE_SPECULAR + USE_LOCAL_VIEWER + USE_TEXTURE_2D + +*/ + + + +#define USE_SPECULAR + + + +#ifdef USE_LIGHTING + +varying vec3 varying_normal; +varying vec3 varying_half_vector; + +#ifndef USE_FAST_LIGHTING +varying vec3 varying_position; +#endif + +#endif + + + +varying vec4 varying_color; + + + +#ifdef USE_TEXTURE_2D +varying vec2 varying_texcoord; +#endif + + + +void main() +{ +#ifdef USE_LIGHTING + /* compute normal */ + vec3 N = normalize(varying_normal); + +#ifdef USE_TWO_SIDE + if (!gl_FrontFacing) + N = -N; +#endif + + /* compute diffuse and specular lighting */ + vec3 L_diffuse = vec3(0,0,0); + +#ifdef USE_SPECULAR + vec3 L_specular = vec3(0,0,0); +#endif + vec3 debug; + +#ifdef USE_FAST_LIGHTING + for (int i = 0; i < b_LightCount; i++) { + vec3 VP; + + /* directional light */ + + VP = b_LightSource[i].position.xyz; /* Assume this is a normalized direction vector for a sun lamp. */ + + /* diffuse light */ + + float NdotVP = dot(N, VP); + + if (NdotVP > 0.0) { + L_diffuse += NdotVP * b_LightSource[i].diffuse.rgb; + +#ifdef USE_SPECULAR + /* specular light */ + + vec3 VE = vec3(0, 0, 1); /* Assume non-local viewer. */ + vec3 HV = normalize(VP + VE); + float NdotHV = dot(N, HV); + + if (NdotHV > 0.0) + L_specular += pow(NdotHV, b_FrontMaterial.shininess) * b_LightSource[i].specular.rgb; +#endif + } + } + +#else /* all 8 lights, makes no assumptions, potentially slow */ + + for (int i = 0; i < 1/*b_LightCount*/; i++) { + float I; + vec3 VP; + + if (b_LightSource[i].position.w == 0.0) { + /* directional light */ + + VP = b_LightSource[i].position.xyz; /* Assume this is a normalized direction vector for a sun lamp. */ + + I = 1; + } + else { + /* point light */ + + VP = b_LightSource[i].position.xyz - varying_position; + + float d = length(VP); + + VP /= d; + + /* spot light cone */ + if (b_LightSource[i].spotCutoff < 90.0) { + float cosine = max(dot(VP, -b_LightSource[i].spotDirection), 0.0); + I = pow(cosine, b_LightSource[i].spotExponent) * step(b_LightSource[i].spotCosCutoff, cosine); + } + else { + I = 1; + } + + I /= + b_LightSource[i].constantAttenuation + + b_LightSource[i].linearAttenuation * d + + b_LightSource[i].quadraticAttenuation * d * d; + } + + float NdotVP = dot(N, VP); + + if (NdotVP > 0) { + L_diffuse += I * NdotVP * b_LightSource[i].diffuse.rgb; + +#ifdef USE_SPECULAR + /* specular light */ + +#ifdef USE_LOCAL_VIEWER + vec3 VE = normalize(-varying_position); +#else + vec3 VE = vec3(0, 0, 1); +#endif + vec3 HV = normalize(VP + VE); /* Assumes VP and VE were normalized already. */ + float NdotHV = dot(N, HV); + + if (NdotHV > 0) + L_specular += I * pow(NdotHV, b_FrontMaterial.shininess) * b_LightSource[i].specular.rgb; +#endif + } + } + +#endif /* fast or regular lighting */ + + /* compute diffuse color, possibly from texture or vertex colors */ + float alpha; + +#ifdef USE_TEXTURE_2D + vec4 texture_color = texture2D(b_Sampler2D[0], varying_texcoord); + + L_diffuse *= texture_color.rgb * varying_color.rgb; + alpha = texture_color.a * varying_color.a; +#else + L_diffuse *= varying_color.rgb; + alpha = varying_color.a; +#endif + + /* sum lighting */ + vec3 L_total = L_diffuse; + +#ifdef USE_SPECULAR + L_total += L_specular * b_FrontMaterial.specular.rgb; +#endif + + /* write out fragment color */ + gl_FragColor = vec4(L_total, alpha); + +#else /* no lighting */ + +#ifdef USE_TEXTURE_2D + gl_FragColor = texture2D(b_Sampler2D[0], varying_texcoord) * varying_color; +#else + gl_FragColor = varying_color; +#endif + +#endif +} diff --git a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl new file mode 100644 index 00000000000..351da073dc3 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl @@ -0,0 +1,64 @@ +/* Options: + + USE_LIGHTING + USE_FAST_LIGHTING + USE_TWO_SIDE + USE_SPECULAR + USE_LOCAL_VIEWER + USE_TEXTURE_2D + +*/ + + + +#ifdef USE_LIGHTING + +varying vec3 varying_normal; + +#ifndef USE_FAST_LIGHTING +varying vec3 varying_position; +#endif + +#endif + + + +varying vec4 varying_color; + + + +#ifdef USE_TEXTURE_2D +varying vec2 varying_texcoord; +#endif + + + +void main() +{ + vec4 co = b_ModelViewMatrix * b_Vertex; + +#ifdef USE_LIGHTING + varying_normal = normalize(b_NormalMatrix * b_Normal); + +#ifndef USE_FAST_LIGHTING + varying_position = co.xyz; +#endif + +#endif + + gl_Position = b_ProjectionMatrix * co; + +#if defined(GPU_PROFILE_COMPAT) && defined(GPU_NVIDIA) + // Setting gl_ClipVertex is necessary to get glClipPlane working on NVIDIA + // graphic cards, while on ATI it can cause a software fallback. + gl_ClipVertex = co; +#endif + + varying_color = b_Color; + +#ifdef USE_TEXTURE_2D + varying_texcoord = (b_TextureMatrix[0] * b_MultiTexCoord0).st; +#endif +} + + diff --git a/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl b/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl new file mode 100644 index 00000000000..71a3ce05a95 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl @@ -0,0 +1,55 @@ +/* begin known attributes */ + +attribute vec4 b_Vertex; + + + +attribute vec4 b_Color; + + + +#ifdef USE_LIGHTING +attribute vec3 b_Normal; +#endif + + + +#ifdef USE_TEXTURE_2D + +#if GPU_MAX_COMMON_TEXCOORDS > 0 +attribute vec4 b_MultiTexCoord0; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 1 +attribute vec4 b_MultiTexCoord1; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 2 +attribute vec4 b_MultiTexCoord2; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 3 +attribute vec4 b_MultiTexCoord3; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 4 +attribute vec4 b_MultiTexCoord4; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 5 +attribute vec4 b_MultiTexCoord5; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 6 +attribute vec4 b_MultiTexCoord6; +#endif + +#if GPU_MAX_COMMON_TEXCOORDS > 7 +attribute vec4 b_MultiTexCoord7; +#endif + +#endif + +/* end known attributes */ + + diff --git a/source/blender/gpu/shaders/gpu_shader_common_constants.glsl b/source/blender/gpu/shaders/gpu_shader_common_constants.glsl new file mode 100644 index 00000000000..44eda3f8666 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_common_constants.glsl @@ -0,0 +1,17 @@ +/* begin common constants */ + +#ifdef USE_TEXTURE_2D +const int b_MaxTextureCoords = GPU_MAX_COMMON_TEXCOORDS; +const int b_MaxCombinedTextureImageUnits = GPU_MAX_COMMON_SAMPLERS; +#endif + +#ifdef USE_LIGHTING +const int b_MaxLights = GPU_MAX_COMMON_LIGHTS; +#endif + +#ifdef USE_CLIP_PLANES +const int b_MaxClipPlanes = GPU_MAX_COMMON_CLIP_PLANES; +#endif + +/* end known constants */ + diff --git a/source/blender/gpu/shaders/gpu_shader_common_uniforms.glsl b/source/blender/gpu/shaders/gpu_shader_common_uniforms.glsl new file mode 100644 index 00000000000..cf8eec653e9 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_common_uniforms.glsl @@ -0,0 +1,63 @@ +/* begin common uniforms */ + +uniform mat4 b_ModelViewMatrix; +uniform mat4 b_ProjectionMatrix; +uniform mat4 b_ModelViewProjectionMatrix; + + +#ifdef USE_TEXTURE_2D + +uniform mat4 b_TextureMatrix[b_MaxTextureCoords]; + +uniform sampler2D b_Sampler2D[b_MaxCombinedTextureImageUnits]; + +#endif + + +#ifdef USE_LIGHTING + +uniform mat3 b_NormalMatrix; // transpose of upper 3x3 of b_ModelViewMatrix + +uniform mat4 b_ModelViewMatrixInverse; + +struct b_MaterialParameters { + vec4 specular; // Scm * Scli + float shininess; // Srm +}; + +uniform b_MaterialParameters b_FrontMaterial; + +struct b_LightSourceParameters { + vec4 diffuse; // Dcli + vec4 specular; // Scli + vec4 position; // Ppli + + vec3 spotDirection; // Sdli + float spotExponent; // Srli + float spotCutoff; // Crli + // (range: [0.0,90.0], 180.0) + + float spotCosCutoff; // Derived: cos(Crli) + // (range: [1.0,0.0],-1.0) + + float constantAttenuation; // K0 + float linearAttenuation; // K1 + float quadraticAttenuation; // K2 +}; + +uniform b_LightSourceParameters b_LightSource[b_MaxLights]; + +uniform int b_LightCount; + +#endif + + +#ifdef USE_CLIP_PLANES + +uniform double b_ClipPlane[b_MaxClipPlanes][4]; + +uniform int b_ClipPlaneCount; + +#endif + +/* end common uniforms */ diff --git a/source/blender/gpu/shaders/gpu_shader_font_frag.glsl b/source/blender/gpu/shaders/gpu_shader_font_frag.glsl new file mode 100644 index 00000000000..213b370580f --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_font_frag.glsl @@ -0,0 +1,11 @@ +varying vec4 varying_color; +varying vec2 varying_texcoord; + +void main() +{ +#ifdef GPU_PROFILE_CORE + gl_FragColor = vec4(varying_color.rgb, texture2D(b_Sampler2D[0], varying_texcoord).r * varying_color.a); +#else + gl_FragColor = vec4(varying_color.rgb, texture2D(b_Sampler2D[0], varying_texcoord).a * varying_color.a); +#endif +} diff --git a/source/blender/gpu/shaders/gpu_shader_font_vert.glsl b/source/blender/gpu/shaders/gpu_shader_font_vert.glsl new file mode 100644 index 00000000000..d6ccd243d16 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_font_vert.glsl @@ -0,0 +1,10 @@ +varying vec4 varying_color; +varying vec2 varying_texcoord; + +void main() +{ + varying_texcoord = (b_TextureMatrix[0] * b_MultiTexCoord0).st; + varying_color = b_Color; + + gl_Position = b_ModelViewProjectionMatrix * b_Vertex; +} diff --git a/source/blender/gpu/shaders/gpu_shader_pixels_frag.glsl b/source/blender/gpu/shaders/gpu_shader_pixels_frag.glsl new file mode 100644 index 00000000000..e51aed39194 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_pixels_frag.glsl @@ -0,0 +1,6 @@ +varying vec2 varying_texcoord; + +void main() +{ + gl_FragColor = texture2D(b_Sampler2D[0], varying_texcoord)*b_Pixels.scale + b_Pixels.bias; +} diff --git a/source/blender/gpu/shaders/gpu_shader_pixels_uniforms.glsl b/source/blender/gpu/shaders/gpu_shader_pixels_uniforms.glsl new file mode 100644 index 00000000000..9bc78586048 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_pixels_uniforms.glsl @@ -0,0 +1,12 @@ +/* begin pixel uniforms */ + +struct b_PixelParameters { + vec4 scale; + vec4 bias; +}; + +uniform b_PixelParameters b_Pixels; + +/* end pixel uniforms */ + + diff --git a/source/blender/gpu/shaders/gpu_shader_pixels_vert.glsl b/source/blender/gpu/shaders/gpu_shader_pixels_vert.glsl new file mode 100644 index 00000000000..f9285672b5f --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_pixels_vert.glsl @@ -0,0 +1,9 @@ +varying vec2 varying_texcoord; + +void main() +{ + varying_texcoord = b_MultiTexCoord0.st; + + //gl_Position = b_ModelViewProjectionMatrix * b_Vertex; + gl_Position = b_ProjectionMatrix * b_ModelViewMatrix * b_Vertex; +} diff --git a/source/blender/gpu/shaders/gpu_shader_raster_frag.glsl b/source/blender/gpu/shaders/gpu_shader_raster_frag.glsl new file mode 100644 index 00000000000..140bf44def5 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_raster_frag.glsl @@ -0,0 +1,10 @@ +varying vec4 varying_color; + +#ifdef USE_LINE_STIPPLE +varying float varying_stipple_parameter; +#endif + +void main() +{ + gl_FragColor = varying_color; +} diff --git a/source/blender/gpu/shaders/gpu_shader_raster_uniforms.glsl b/source/blender/gpu/shaders/gpu_shader_raster_uniforms.glsl new file mode 100644 index 00000000000..404b8234252 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_raster_uniforms.glsl @@ -0,0 +1,3 @@ +#ifdef USE_POLYGON_STIPPLE +uniform sampler2D b_Stipple; +#endif diff --git a/source/blender/gpu/shaders/gpu_shader_raster_vert.glsl b/source/blender/gpu/shaders/gpu_shader_raster_vert.glsl new file mode 100644 index 00000000000..6ddfaa86612 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_raster_vert.glsl @@ -0,0 +1,17 @@ +varying vec4 varying_color; + +#ifdef USE_LINE_STIPPLE +attribute float b_StippleParameter; +#endif + +void main() +{ + //varying_color = b_Color; + varying_color = vec4(1,0,1,1); + +#ifdef USE_LINE_STIPPLE + varying_stipple_parameter = b_StippleParameter; +#endif + + gl_Position = b_ModelViewProjectionMatrix * b_Vertex; +} diff --git a/source/blender/gpu/shaders/gpu_shader_simple_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_frag.glsl deleted file mode 100644 index 94c73d9e248..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_simple_frag.glsl +++ /dev/null @@ -1,169 +0,0 @@ - -/* Options: - * - * USE_COLOR: use glColor for diffuse colors - * USE_TEXTURE: use texture for diffuse colors - * USE_SCENE_LIGHTING: use lights (up to 8) - * USE_SOLID_LIGHTING: assume 3 directional lights for solid draw mode - * USE_TWO_SIDED: flip normal towards viewer - * NO_SPECULAR: use specular component - */ - -#define NUM_SOLID_LIGHTS 3 -#define NUM_SCENE_LIGHTS 8 - -#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING) -varying vec3 varying_normal; - -#ifndef USE_SOLID_LIGHTING -varying vec3 varying_position; -#endif -#endif - -#ifdef USE_COLOR -varying vec4 varying_vertex_color; -#endif - -#ifdef USE_TEXTURE -varying vec2 varying_texture_coord; -uniform sampler2D texture_map; -#endif - -void main() -{ -#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING) - /* compute normal */ - vec3 N = normalize(varying_normal); - -#ifdef USE_TWO_SIDED - if (!gl_FrontFacing) - N = -N; -#endif - - /* compute diffuse and specular lighting */ - vec3 L_diffuse = vec3(0.0); -#ifndef NO_SPECULAR - vec3 L_specular = vec3(0.0); -#endif - -#ifdef USE_SOLID_LIGHTING - /* assume 3 directional lights */ - for (int i = 0; i < NUM_SOLID_LIGHTS; i++) { - vec3 light_direction = gl_LightSource[i].position.xyz; - - /* diffuse light */ - vec3 light_diffuse = gl_LightSource[i].diffuse.rgb; - float diffuse_bsdf = max(dot(N, light_direction), 0.0); - L_diffuse += light_diffuse*diffuse_bsdf; - -#ifndef NO_SPECULAR - /* specular light */ - vec3 light_specular = gl_LightSource[i].specular.rgb; - vec3 H = gl_LightSource[i].halfVector.xyz; - - float specular_bsdf = pow(max(dot(N, H), 0.0), gl_FrontMaterial.shininess); - L_specular += light_specular*specular_bsdf; -#endif - } -#else - /* all 8 lights, makes no assumptions, potentially slow */ - -#ifndef NO_SPECULAR - /* view vector computation, depends on orthographics or perspective */ - vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position): vec3(0.0, 0.0, -1.0); -#endif - - for (int i = 0; i < NUM_SCENE_LIGHTS; i++) { - /* todo: this is a slow check for disabled lights */ - if (gl_LightSource[i].specular.a == 0.0) - continue; - - float intensity = 1.0; - vec3 light_direction; - - if (gl_LightSource[i].position.w == 0.0) { - /* directional light */ - light_direction = gl_LightSource[i].position.xyz; - } - else { - /* point light */ - vec3 d = gl_LightSource[i].position.xyz - varying_position; - light_direction = normalize(d); - - /* spot light cone */ - if (gl_LightSource[i].spotCutoff < 90.0) { - float cosine = max(dot(light_direction, -gl_LightSource[i].spotDirection), 0.0); - intensity = pow(cosine, gl_LightSource[i].spotExponent); - intensity *= step(gl_LightSource[i].spotCosCutoff, cosine); - } - - /* falloff */ - float distance = length(d); - - intensity /= gl_LightSource[i].constantAttenuation + - gl_LightSource[i].linearAttenuation * distance + - gl_LightSource[i].quadraticAttenuation * distance * distance; - } - - /* diffuse light */ - vec3 light_diffuse = gl_LightSource[i].diffuse.rgb; - float diffuse_bsdf = max(dot(N, light_direction), 0.0); - L_diffuse += light_diffuse*diffuse_bsdf*intensity; - -#ifndef NO_SPECULAR - /* specular light */ - vec3 light_specular = gl_LightSource[i].specular.rgb; - vec3 H = normalize(light_direction - V); - - float specular_bsdf = pow(max(dot(N, H), 0.0), gl_FrontMaterial.shininess); - L_specular += light_specular*specular_bsdf*intensity; -#endif - } -#endif - - /* compute diffuse color, possibly from texture or vertex colors */ - float alpha; - -#if defined(USE_TEXTURE) && defined(USE_COLOR) - vec4 texture_color = texture2D(texture_map, varying_texture_coord); - - L_diffuse *= texture_color.rgb * varying_vertex_color.rgb; - alpha = texture_color.a * varying_vertex_color.a; -#elif defined(USE_TEXTURE) - vec4 texture_color = texture2D(texture_map, varying_texture_coord); - - L_diffuse *= texture_color.rgb; - alpha = texture_color.a; -#elif defined(USE_COLOR) - L_diffuse *= varying_vertex_color.rgb; - alpha = varying_vertex_color.a; -#else - L_diffuse *= gl_FrontMaterial.diffuse.rgb; - alpha = gl_FrontMaterial.diffuse.a; -#endif - - /* sum lighting */ - vec3 L = gl_FrontLightModelProduct.sceneColor.rgb + L_diffuse; - -#ifndef NO_SPECULAR - L += L_specular*gl_FrontMaterial.specular.rgb; -#endif - - /* write out fragment color */ - gl_FragColor = vec4(L, alpha); -#else - - /* no lighting */ -#if defined(USE_TEXTURE) && defined(USE_COLOR) - gl_FragColor = texture2D(texture_map, varying_texture_coord) * varying_vertex_color; -#elif defined(USE_TEXTURE) - gl_FragColor = texture2D(texture_map, varying_texture_coord); -#elif defined(USE_COLOR) - gl_FragColor = varying_vertex_color; -#else - gl_FragColor = gl_FrontMaterial.diffuse; -#endif - -#endif -} - diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 15f5253257a..e6bd9fb79b4 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -287,6 +287,7 @@ blender_include_dirs( ../../../../intern/audaspace/intern ../../../../intern/cycles/blender ../../../../intern/guardedalloc + ../../../../intern/glew-mx ../../../../intern/atomic ../../../../intern/memutil ../../../../intern/smoke/extern @@ -322,4 +323,6 @@ set(SRC rna_mesh_utils.h ) +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(bf_rna "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index b841356709e..584df9eee75 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -40,7 +40,6 @@ set(INC set(INC_SYS ${ZLIB_INCLUDE_DIRS} - ${GLEW_INCLUDE_PATH} ) set(SRC diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 2293415aef0..9eb6c1674a3 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -38,6 +38,7 @@ set(INC ../makesrna ../render/extern/include ../../../intern/guardedalloc + ../../../intern/glew-mx ) set(INC_SYS @@ -279,6 +280,8 @@ if(WITH_COMPOSITOR) add_definitions(-DWITH_COMPOSITOR) endif() +add_definitions(${GL_DEFINITIONS}) + if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) endif() diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt index aec2faa89e6..155247a4249 100644 --- a/source/blender/python/generic/CMakeLists.txt +++ b/source/blender/python/generic/CMakeLists.txt @@ -22,8 +22,10 @@ set(INC . ../../blenkernel ../../blenlib + ../../gpu ../../makesdna ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS @@ -46,6 +48,6 @@ set(SRC py_capi_utils.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) blender_add_lib(bf_python_ext "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index b8dcf9d8491..08b8fa28db4 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -30,10 +30,12 @@ * This module is very similar to 'PyOpenGL' which could replace 'bgl' one day. */ +#define GPU_MANGLE_DEPRECATED 0 + #include <Python.h> #include "bgl.h" /*This must come first */ -#include <GL/glew.h> +#include "GPU_glew.h" #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 70b4df7d6fe..a75db23d20b 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -260,5 +260,6 @@ if(WITH_PLAYER) add_definitions(-DWITH_PLAYER) endif() +add_definitions(${GL_DEFINITIONS}) blender_add_lib(bf_python "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 5f993297840..088bddc8a76 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -40,12 +40,12 @@ set(INC ../../gameengine/BlenderRoutines ../../../intern/ghost ../../../intern/guardedalloc + ../../../intern/glew-mx ../../../intern/memutil ) set(INC_SYS ${ZLIB_INCLUDE_DIRS} - ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_PATH} ) @@ -78,7 +78,7 @@ set(SRC wm_window.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) @@ -107,6 +107,8 @@ endif() if(WITH_HEADLESS) add_definitions(-DWITH_HEADLESS) +elseif(WITH_X11) + add_definitions(-DWITH_X11) endif() if(WITH_PYTHON) diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 2f20e8c234f..7440570f4a0 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -32,7 +32,6 @@ #include <stdlib.h> #include <string.h> -#include <GL/glew.h> #include "DNA_listBase.h" #include "DNA_screen_types.h" @@ -57,6 +56,7 @@ #include "GPU_draw.h" #include "GPU_extensions.h" +#include "GPU_glew.h" #include "RE_engine.h" diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index b1f693502f6..6720bf89c77 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -110,6 +110,7 @@ #include "GPU_buffers.h" #include "GPU_extensions.h" #include "GPU_draw.h" +#include "GPU_init_exit.h" #include "BKE_depsgraph.h" #include "BKE_sound.h" @@ -135,11 +136,11 @@ bool wm_start_with_console = false; /* used in creator.c */ /* only called once, for startup */ void WM_init(bContext *C, int argc, const char **argv) { - if (!G.background) { wm_ghost_init(C); /* note: it assigns C to ghost! */ wm_init_cursor_data(); } + GHOST_CreateSystemPaths(); BKE_addon_pref_type_init(); @@ -195,7 +196,8 @@ void WM_init(bContext *C, int argc, const char **argv) wm_init_reports(C); /* reports cant be initialized before the wm */ if (!G.background) { - GPU_extensions_init(); + GPU_init(); + GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP)); GPU_set_anisotropic(U.anisotropic_filter); GPU_set_gpu_mipmapping(U.use_gpu_mipmap); @@ -206,8 +208,6 @@ void WM_init(bContext *C, int argc, const char **argv) clear_matcopybuf(); ED_render_clear_mtex_copybuf(); - // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - ED_preview_init_dbase(); wm_read_history(); @@ -502,9 +502,8 @@ void WM_exit_ext(bContext *C, const bool do_python) if (!G.background) { GPU_global_buffer_pool_free(); GPU_free_unused_buffers(); - GPU_extensions_exit(); + GPU_exit(); } - BKE_reset_undo(); ED_file_exit(); /* for fsmenu */ diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 024135e73e9..1cf62ce3a10 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -274,7 +274,6 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf /* checkerboard for case alpha */ if (ibuf->planes == 32) { glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); fdrawcheckerboard(offsx, offsy, offsx + (ps->zoom * ibuf->x) / (float)ps->win_x, offsy + (ps->zoom * ibuf->y) / (float)ps->win_y); } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 56e094891f5..d83f876c2e1 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -55,7 +55,6 @@ #include "BKE_global.h" #include "BKE_main.h" -#include "BIF_gl.h" #include "RNA_access.h" @@ -74,6 +73,8 @@ #include "GPU_draw.h" #include "GPU_extensions.h" +#include "GPU_init_exit.h" +#include "GPU_glew.h" #include "UI_interface.h" @@ -319,8 +320,7 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win) /* nothing to do for 'temp' windows, * because WM_window_open_temp always sets window title */ } - else { - + else if (win->ghostwin) { /* this is set to 1 if you don't have startup.blend open */ if (G.save_over && G.main->name[0]) { char str[sizeof(G.main->name) + 24]; @@ -345,34 +345,34 @@ static void wm_window_add_ghostwindow(const char *title, wmWindow *win) GHOST_WindowHandle ghostwin; static int multisamples = -1; int scr_w, scr_h, posy; - + /* force setting multisamples only once, it requires restart - and you cannot * mix it, either all windows have it, or none (tested in OSX opengl) */ if (multisamples == -1) multisamples = U.ogl_multisamples; - + wm_get_screensize(&scr_w, &scr_h); posy = (scr_h - win->posy - win->sizey); - + ghostwin = GHOST_CreateWindow(g_system, title, win->posx, posy, win->sizex, win->sizey, (GHOST_TWindowState)win->windowstate, GHOST_kDrawingContextTypeOpenGL, 0 /* no stereo */, multisamples /* AA */); - + if (ghostwin) { GHOST_RectangleHandle bounds; - + /* needed so we can detect the graphics card below */ - GPU_extensions_init(); - + GPU_init(); + win->ghostwin = ghostwin; GHOST_SetWindowUserData(ghostwin, win); /* pointer back */ - + if (win->eventstate == NULL) win->eventstate = MEM_callocN(sizeof(wmEvent), "window event state"); - + #ifdef __APPLE__ /* set the state here, else OSX would not recognize changed screen resolution */ /* we agreed to not set any fullscreen or iconized state on startup */ @@ -394,16 +394,16 @@ static void wm_window_add_ghostwindow(const char *title, wmWindow *win) if (!GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE)) { glClear(GL_COLOR_BUFFER_BIT); } - + /* displays with larger native pixels, like Macbook. Used to scale dpi with */ /* needed here, because it's used before it reads userdef */ U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin); BKE_userdef_state(); - + wm_window_swap_buffers(win); - + //GHOST_SetWindowState(ghostwin, GHOST_kWindowStateModified); - + /* standard state vars for window */ glEnable(GL_SCISSOR_TEST); GPU_state_init(); @@ -425,14 +425,13 @@ void wm_window_add_ghostwindows(wmWindowManager *wm) if (wm_init_state.size_x == 0) { wm_get_screensize(&wm_init_state.size_x, &wm_init_state.size_y); - /* note!, this isnt quite correct, active screen maybe offset 1000s if PX, - * we'd need a wm_get_screensize like function that gives offset, - * in practice the window manager will likely move to the correct monitor */ - wm_init_state.start_x = 0; - wm_init_state.start_y = 0; - + /* note!, this isnt quite correct, active screen maybe offset 1000s if PX, + * we'd need a wm_get_screensize like function that gives offset, + * in practice the window manager will likely move to the correct monitor */ + wm_init_state.start_x = 0; + wm_init_state.start_y = 0; -#if !defined(__APPLE__) && !defined(WIN32) /* X11 */ +#if WITH_X11 /* X11 */ /* X11, start maximized but use default sane size */ wm_init_state.size_x = min_ii(wm_init_state.size_x, WM_WIN_INIT_SIZE_X); wm_init_state.size_y = min_ii(wm_init_state.size_y, WM_WIN_INIT_SIZE_Y); @@ -1413,9 +1412,9 @@ void wm_window_set_swap_interval (wmWindow *win, int interval) GHOST_SetSwapInterval(win->ghostwin, interval); } -int wm_window_get_swap_interval (wmWindow *win) +bool wm_window_get_swap_interval (wmWindow *win, int* intervalOut) { - return GHOST_GetSwapInterval(win->ghostwin); + return GHOST_GetSwapInterval(win->ghostwin, intervalOut); } diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index e0639b098a8..02852a80aa2 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -59,7 +59,7 @@ void wm_window_set_size (wmWindow *win, int width, int height); void wm_window_get_position (wmWindow *win, int *posx_r, int *posy_r); void wm_window_swap_buffers (wmWindow *win); void wm_window_set_swap_interval (wmWindow *win, int interval); -int wm_window_get_swap_interval (wmWindow *win); +bool wm_window_get_swap_interval (wmWindow *win, int* intervalOut); void wm_get_cursor_position (wmWindow *win, int *x, int *y); diff --git a/source/blenderplayer/CMakeLists.txt b/source/blenderplayer/CMakeLists.txt index 188fb01d23d..ce20371d91b 100644 --- a/source/blenderplayer/CMakeLists.txt +++ b/source/blenderplayer/CMakeLists.txt @@ -162,7 +162,7 @@ endif() endif() if(NOT WITH_SYSTEM_GLEW) - list(APPEND BLENDER_SORTED_LIBS extern_glew) + list(APPEND BLENDER_SORTED_LIBS ${BLENDER_GLEW_LIBRARIES}) endif() if(WITH_LZMA) diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 6ed87f6596c..bd9dce01ed8 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -27,6 +27,7 @@ setup_libdirs() blender_include_dirs( ../../intern/guardedalloc + ../../intern/glew-mx ../blender/blenlib ../blender/blenkernel ../blender/blenloader @@ -39,6 +40,9 @@ blender_include_dirs( ../blender/windowmanager ) +add_definitions(${GL_DEFINITIONS}) +blender_include_dirs(${GLEW_INCLUDE_PATH}) + if(WIN32) blender_include_dirs(../../intern/utfconv) endif() @@ -671,6 +675,18 @@ elseif(WIN32) unset(_PYTHON_VERSION_NO_DOTS) endif() + # OpenGL ES Runtime Components + if(WITH_GL_CONTEXT_EMBEDDED) + if(WIN32) + install(FILES "${OPENGLES_DLL}" DESTINATION ${TARGETDIR}) + install(FILES "${OPENGLES_EGL_DLL}" DESTINATION ${TARGETDIR}) + + if(WITH_ANGLE) + install(FILES "${D3DCOMPILER_DLL}" DESTINATION ${TARGETDIR}) + endif() + endif() + endif() + if(MSVC) install( FILES ${LIBDIR}/pthreads/lib/pthreadVC2.dll diff --git a/source/creator/creator.c b/source/creator/creator.c index 412ff374233..10f82b90516 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -1583,21 +1583,6 @@ int main( #endif setCallbacks(); -#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE) - /* patch to ignore argument finder gives us (pid?) */ - if (argc == 2 && strncmp(argv[1], "-psn_", 5) == 0) { - extern int GHOST_HACK_getFirstFile(char buf[]); - static char firstfilebuf[512]; - - argc = 1; - - if (GHOST_HACK_getFirstFile(firstfilebuf)) { - argc = 2; - argv[1] = firstfilebuf; - } - } - -#endif #ifdef __FreeBSD__ fpsetmask(0); diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 298b16af43b..a7c98eb9dc1 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -40,7 +40,7 @@ # pragma warning (disable:4786) #endif -#include "GL/glew.h" +#include "glew-mx.h" #include "KX_BlenderCanvas.h" #include "KX_BlenderKeyboardDevice.h" @@ -294,7 +294,8 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE); // Setup vsync - int previous_vsync = canvas->GetSwapInterval(); + int previous_vsync = 0; + canvas->GetSwapInterval(previous_vsync); if (startscene->gm.vsync == VSYNC_ADAPTIVE) canvas->SetSwapInterval(-1); else diff --git a/source/gameengine/BlenderRoutines/CMakeLists.txt b/source/gameengine/BlenderRoutines/CMakeLists.txt index 73dbe005518..1a2809cc8ab 100644 --- a/source/gameengine/BlenderRoutines/CMakeLists.txt +++ b/source/gameengine/BlenderRoutines/CMakeLists.txt @@ -24,6 +24,7 @@ set(INC ../../blender/makesrna ../../blender/windowmanager ../../../intern/container + ../../../intern/glew-mx ../../../intern/guardedalloc ../../../intern/string ) @@ -52,7 +53,7 @@ set(SRC KX_BlenderSystem.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_AUDASPACE) list(APPEND INC diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index b3e0b4c3ea6..a3f528d7110 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -29,7 +29,7 @@ * \ingroup blroutines */ -#include <GL/glew.h> +#include "glew-mx.h" #include "MEM_guardedalloc.h" @@ -91,9 +91,9 @@ void KX_BlenderCanvas::SetSwapInterval(int interval) wm_window_set_swap_interval(m_win, interval); } -int KX_BlenderCanvas::GetSwapInterval() +bool KX_BlenderCanvas::GetSwapInterval(int& intervalOut) { - return wm_window_get_swap_interval(m_win); + return wm_window_get_swap_interval(m_win, &intervalOut); } void KX_BlenderCanvas::ResizeWindow(int width, int height) diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h index 9ad80cb1737..237be1c3f45 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h @@ -82,8 +82,9 @@ public: int interval ); - int + bool GetSwapInterval( + int& intervalOut ); void diff --git a/source/gameengine/GamePlayer/common/CMakeLists.txt b/source/gameengine/GamePlayer/common/CMakeLists.txt index fd73b4efb53..e6c980de566 100644 --- a/source/gameengine/GamePlayer/common/CMakeLists.txt +++ b/source/gameengine/GamePlayer/common/CMakeLists.txt @@ -47,6 +47,7 @@ set(INC ../../../blender/makesdna ../../../../intern/container ../../../../intern/ghost + ../../../../intern/glew-mx ../../../../intern/guardedalloc ../../../../intern/string ) @@ -69,6 +70,6 @@ set(SRC GPC_MouseDevice.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) blender_add_lib_nolist(ge_player_common "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h index bd50066a212..338f9647b3e 100644 --- a/source/gameengine/GamePlayer/common/GPC_Canvas.h +++ b/source/gameengine/GamePlayer/common/GPC_Canvas.h @@ -40,7 +40,7 @@ # include <windows.h> #endif /* WIN32 */ -#include "GL/glew.h" +#include "glew-mx.h" #include <map> diff --git a/source/gameengine/GamePlayer/ghost/CMakeLists.txt b/source/gameengine/GamePlayer/ghost/CMakeLists.txt index df752799c2c..8ab090eac02 100644 --- a/source/gameengine/GamePlayer/ghost/CMakeLists.txt +++ b/source/gameengine/GamePlayer/ghost/CMakeLists.txt @@ -48,6 +48,7 @@ set(INC ../../../blender/makesrna ../../../../intern/container ../../../../intern/ghost + ../../../../intern/glew-mx ../../../../intern/guardedalloc ../../../../intern/string ../../../../intern/memutil @@ -73,7 +74,7 @@ set(SRC GPG_System.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_CODEC_FFMPEG) add_definitions(-DWITH_FFMPEG) diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index b85d4b40ca8..d7a63c28da3 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -36,8 +36,9 @@ # include <windows.h> #endif -#include "GL/glew.h" +#include "glew-mx.h" #include "GPU_extensions.h" +#include "GPU_init_exit.h" #include "GPG_Application.h" #include "BL_BlenderDataConversion.h" @@ -545,7 +546,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) { if (!m_engineInitialized) { - GPU_extensions_init(); + GPU_init(); bgl::InitExtensions(true); // get and set the preferences @@ -867,7 +868,7 @@ void GPG_Application::exitEngine() m_canvas = 0; } - GPU_extensions_exit(); + GPU_exit(); #ifdef WITH_PYTHON // Call this after we're sure nothing needs Python anymore (e.g., destructors) diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp index 35c7c62a67d..556f85804ea 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp @@ -113,12 +113,12 @@ void GPG_Canvas::SetSwapInterval(int interval) m_window->setSwapInterval(interval); } -int GPG_Canvas::GetSwapInterval() +bool GPG_Canvas::GetSwapInterval(int& intervalOut) { if (m_window) - return m_window->getSwapInterval(); + return (bool)m_window->getSwapInterval(intervalOut); - return 0; + return false; } void GPG_Canvas::ResizeWindow(int width, int height) diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h index 6e1f86cac0e..337c2cedf55 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h @@ -56,7 +56,7 @@ public: virtual void SetMouseState(RAS_MouseState mousestate); virtual void SwapBuffers(); virtual void SetSwapInterval(int interval); - virtual int GetSwapInterval(); + virtual bool GetSwapInterval(int& intervalOut); virtual int GetMouseX(int x) { return x; } virtual int GetMouseY(int y) { return y; } diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index b6456b105c8..e880861ea95 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -811,14 +811,6 @@ int main(int argc, char** argv) if (scr_saver_mode != SCREEN_SAVER_MODE_CONFIGURATION) #endif { - - if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0)) { - GPU_set_mipmap(0); - } - - GPU_set_anisotropic(U.anisotropic_filter); - GPU_set_gpu_mipmapping(U.use_gpu_mipmap); - // Create the system if (GHOST_ISystem::createSystem() == GHOST_kSuccess) { GHOST_ISystem* system = GHOST_ISystem::getSystem(); @@ -1041,6 +1033,13 @@ int main(int argc, char** argv) else app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight, stereoWindow, stereomode, aasamples); + + if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0)) { + GPU_set_mipmap(0); + } + + GPU_set_anisotropic(U.anisotropic_filter); + GPU_set_gpu_mipmapping(U.use_gpu_mipmap); } } } diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 872ac19351d..a59c3686a18 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -22,7 +22,7 @@ * \ingroup ketsji */ -#include "GL/glew.h" +#include "glew-mx.h" #include <iostream> #include "BL_Shader.h" diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index 1578c745b9f..1a78efb3c18 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -22,7 +22,7 @@ * \ingroup ketsji */ -#include "GL/glew.h" +#include "glew-mx.h" #include <iostream> #include <map> diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 03d1524b310..44532e5d737 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -49,6 +49,7 @@ set(INC ../../blender/python/generic ../../blender/python/mathutils ../../../intern/container + ../../../intern/glew-mx ../../../intern/guardedalloc ../../../intern/string ) @@ -229,7 +230,7 @@ set(SRC ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) if(WITH_IMAGE_DDS) add_definitions(-DWITH_DDS) diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 9ebdfea6156..9f0b582045f 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -22,7 +22,7 @@ * \ingroup ketsji */ -#include "GL/glew.h" +#include "glew-mx.h" #include "KX_BlenderMaterial.h" #include "BL_Material.h" diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 4ab768e4240..e0761154ed2 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -31,7 +31,7 @@ */ -#include "GL/glew.h" +#include "glew-mx.h" #include "KX_Camera.h" #include "KX_Scene.h" #include "KX_PythonInit.h" diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index c7f7f586865..a77269c116d 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -41,7 +41,7 @@ #include "RAS_CameraData.h" #include "BLI_math.h" -#include "GL/glew.h" +#include "glew-mx.h" // constructor KX_Dome::KX_Dome ( diff --git a/source/gameengine/Ketsji/KX_Dome.h b/source/gameengine/Ketsji/KX_Dome.h index a7e798a3944..420565e62f6 100644 --- a/source/gameengine/Ketsji/KX_Dome.h +++ b/source/gameengine/Ketsji/KX_Dome.h @@ -38,7 +38,7 @@ #include "RAS_IRasterizer.h" #include "KX_KetsjiEngine.h" -#include "GL/glew.h" +#include "glew-mx.h" #include <vector> #include "MEM_guardedalloc.h" diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index da8a0c0844e..fefc64b4bad 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -30,7 +30,7 @@ * \ingroup ketsji */ -#include "GL/glew.h" +#include "glew-mx.h" #ifdef _MSC_VER # pragma warning (disable:4786) @@ -1396,7 +1396,9 @@ static PyObject *gPySetVsync(PyObject *, PyObject *args) static PyObject *gPyGetVsync(PyObject *) { - return PyLong_FromLong(gp_Canvas->GetSwapInterval()); + int interval = 0; + gp_Canvas->GetSwapInterval(interval); + return PyLong_FromLong(interval); } static PyObject *gPyShowFramerate(PyObject *, PyObject *args) diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index fbaa7bb59ba..e52dc1ba052 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -40,6 +40,7 @@ set(INC ../../../blender/makesdna ../../../../intern/container ../../../../intern/guardedalloc + ../../../../intern/glew-mx ../../../../intern/string ) @@ -66,4 +67,6 @@ if(WITH_BULLET) add_definitions(-DWITH_BULLET) endif() +add_definitions(${GL_DEFINITIONS}) + blender_add_lib(ge_phys_bullet "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/Rasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/CMakeLists.txt index e254bf9b1c5..5bc3f22e327 100644 --- a/source/gameengine/Rasterizer/CMakeLists.txt +++ b/source/gameengine/Rasterizer/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../../blender/blenlib ../../blender/blenkernel ../../../intern/container + ../../../intern/glew-mx ../../../intern/guardedalloc ../../../intern/string ) @@ -81,6 +82,6 @@ set(SRC RAS_OpenGLFilters/RAS_Sobel2DFilter.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) blender_add_lib(ge_rasterizer "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index abbe65738d4..908c5979249 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -43,7 +43,7 @@ #include "RAS_2DFilterManager.h" #include <iostream> -#include "GL/glew.h" +#include "glew-mx.h" #include <stdio.h> diff --git a/source/gameengine/Rasterizer/RAS_ICanvas.h b/source/gameengine/Rasterizer/RAS_ICanvas.h index 9e8a6e8ccf6..d90cbea286e 100644 --- a/source/gameengine/Rasterizer/RAS_ICanvas.h +++ b/source/gameengine/Rasterizer/RAS_ICanvas.h @@ -113,8 +113,9 @@ public: )=0; virtual - int + bool GetSwapInterval( + int& intervalOut )=0; virtual diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt index f0410ba891d..888a7114f50 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt @@ -39,6 +39,7 @@ set(INC ../../../blender/gpu ../../../blender/makesdna ../../../../intern/container + ../../../../intern/glew-mx ../../../../intern/string ) @@ -66,6 +67,6 @@ set(SRC RAS_StorageVBO.h ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) blender_add_lib(ge_oglrasterizer "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp index 32cc4ba9fea..bc22d68e218 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp @@ -32,7 +32,7 @@ #include <iostream> -#include "GL/glew.h" +#include "glew-mx.h" #include "RAS_GLExtensionManager.h" diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp index e1dbd6f0a7f..b3da5e1f812 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp @@ -30,7 +30,7 @@ #include <windows.h> #endif // WIN32 -#include "GL/glew.h" +#include "glew-mx.h" #include "RAS_MaterialBucket.h" #include "RAS_TexVert.h" diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp index e1b7a2151c5..4ac1c9c4ebb 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp @@ -25,9 +25,10 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include "glew-mx.h" + #include <stdio.h> -#include "GL/glew.h" #include "RAS_OpenGLLight.h" #include "RAS_OpenGLRasterizer.h" diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 0960fdaab4f..415ea87fb1b 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -35,7 +35,7 @@ #include "RAS_OpenGLRasterizer.h" -#include "GL/glew.h" +#include "glew-mx.h" #include "RAS_ICanvas.h" #include "RAS_Rect.h" diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp index c8975c245cb..e0613350b77 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp @@ -29,7 +29,7 @@ #include "RAS_MaterialBucket.h" #include "RAS_IPolygonMaterial.h" -#include "GL/glew.h" +#include "glew-mx.h" #include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_material.h" diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp index 006c07b0491..c2980a6c15f 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp @@ -27,7 +27,7 @@ #include "RAS_StorageVA.h" -#include "GL/glew.h" +#include "glew-mx.h" RAS_StorageVA::RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer) : m_drawingmode(RAS_IRasterizer::KX_TEXTURED), diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp index 6aa90fbd6ef..58f3d4c05da 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp @@ -28,7 +28,7 @@ #include "RAS_StorageVBO.h" #include "RAS_MeshObject.h" -#include "GL/glew.h" +#include "glew-mx.h" VBO::VBO(RAS_DisplayArray *data, unsigned int indices) { diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h index 2fe0c32f399..f156722247c 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h @@ -29,7 +29,7 @@ #define __KX_VERTEXBUFFEROBJECTSTORAGE #include <map> -#include "GL/glew.h" +#include "glew-mx.h" #include "RAS_IStorage.h" #include "RAS_IRasterizer.h" diff --git a/source/gameengine/VideoTexture/CMakeLists.txt b/source/gameengine/VideoTexture/CMakeLists.txt index 3ca3917cf6d..4be9a9abe5c 100644 --- a/source/gameengine/VideoTexture/CMakeLists.txt +++ b/source/gameengine/VideoTexture/CMakeLists.txt @@ -42,6 +42,7 @@ set(INC ../../blender/python/generic ../../../intern/container ../../../intern/ffmpeg + ../../../intern/glew-mx ../../../intern/guardedalloc ../../../intern/string ) @@ -51,7 +52,7 @@ set(INC_SYS ${GLEW_INCLUDE_PATH} ) -add_definitions(-DGLEW_STATIC) +add_definitions(${GL_DEFINITIONS}) set(SRC Exception.cpp diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp index 4109981a98c..0d46160a11e 100644 --- a/source/gameengine/VideoTexture/ImageBase.cpp +++ b/source/gameengine/VideoTexture/ImageBase.cpp @@ -32,7 +32,7 @@ extern "C" { #include "bgl.h" } -#include "GL/glew.h" +#include "glew-mx.h" #include <vector> #include <string.h> diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 8c6dcf45d6f..617e7fd1d8e 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -36,7 +36,7 @@ #include <math.h> -#include "GL/glew.h" +#include "glew-mx.h" #include "KX_PythonInit.h" #include "DNA_scene_types.h" diff --git a/source/gameengine/VideoTexture/ImageViewport.cpp b/source/gameengine/VideoTexture/ImageViewport.cpp index 789b6006f99..421f0df814b 100644 --- a/source/gameengine/VideoTexture/ImageViewport.cpp +++ b/source/gameengine/VideoTexture/ImageViewport.cpp @@ -33,7 +33,7 @@ #include "PyObjectPlus.h" #include <structmember.h> -#include "GL/glew.h" +#include "glew-mx.h" #include "KX_PythonInit.h" #include "RAS_ICanvas.h" diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp index 35a73193a24..74f36207774 100644 --- a/source/gameengine/VideoTexture/Texture.cpp +++ b/source/gameengine/VideoTexture/Texture.cpp @@ -54,7 +54,7 @@ #include "Exception.h" #include <memory.h> -#include "GL/glew.h" +#include "glew-mx.h" // macro for exception handling and logging |