Revision: 15576 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15576 Author: blendix Date: 2008-07-15 01:26:38 +0200 (Tue, 15 Jul 2008)
Log Message: ----------- Apricot: GLSL ============= * Added options to disable lights, shaders, shadows, ramps, nodes and textures other than col/alpha for GLSL, in the Game menu. * These have python access too to switch them in game, but it doesn't work correct yet with display lists enabled. * Fix issue with light lagging behind, debug stats drawing in wrong color, and a number of other small fixes. Modified Paths: -------------- branches/apricot/source/blender/blenkernel/BKE_global.h branches/apricot/source/blender/gpu/GPU_material.h branches/apricot/source/blender/gpu/intern/gpu_codegen.c branches/apricot/source/blender/gpu/intern/gpu_codegen.h branches/apricot/source/blender/gpu/intern/gpu_extensions.c branches/apricot/source/blender/gpu/intern/gpu_material.c branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl.c branches/apricot/source/blender/python/SConscript branches/apricot/source/blender/python/api2_2x/Blender.c branches/apricot/source/blender/src/drawobject.c branches/apricot/source/blender/src/header_info.c branches/apricot/source/blender/src/space.c branches/apricot/source/gameengine/Converter/BL_BlenderDataConversion.cpp branches/apricot/source/gameengine/GamePlayer/ghost/GPG_Application.cpp branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.cpp branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.h branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.cpp branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.h branches/apricot/source/gameengine/Ketsji/KX_Light.cpp branches/apricot/source/gameengine/Ketsji/KX_Light.h branches/apricot/source/gameengine/Ketsji/KX_Scene.cpp branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp Modified: branches/apricot/source/blender/blenkernel/BKE_global.h =================================================================== --- branches/apricot/source/blender/blenkernel/BKE_global.h 2008-07-14 22:23:39 UTC (rev 15575) +++ branches/apricot/source/blender/blenkernel/BKE_global.h 2008-07-14 23:26:38 UTC (rev 15576) @@ -218,9 +218,15 @@ #define G_FILE_NO_UI (1 << 10) #define G_FILE_GAME_TO_IPO (1 << 11) #define G_FILE_GAME_MAT (1 << 12) -#define G_FILE_DIAPLAY_LISTS (1 << 13) +#define G_FILE_DISPLAY_LISTS (1 << 13) #define G_FILE_SHOW_PHYSICS (1 << 14) #define G_FILE_GAME_MAT_GLSL (1 << 15) +#define G_FILE_GLSL_NO_LIGHTS (1 << 16) +#define G_FILE_GLSL_NO_SHADERS (1 << 17) +#define G_FILE_GLSL_NO_SHADOWS (1 << 18) +#define G_FILE_GLSL_NO_RAMPS (1 << 19) +#define G_FILE_GLSL_NO_NODES (1 << 20) +#define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21) /* G.windowstate */ #define G_WINDOWSTATE_USERDEF 0 Modified: branches/apricot/source/blender/gpu/GPU_material.h =================================================================== --- branches/apricot/source/blender/gpu/GPU_material.h 2008-07-14 22:23:39 UTC (rev 15575) +++ branches/apricot/source/blender/gpu/GPU_material.h 2008-07-14 23:26:38 UTC (rev 15576) @@ -44,6 +44,7 @@ struct Lamp; struct bNode; struct LinkNode; +struct Scene; struct GPUVertexAttribs; struct GPUNode; struct GPUNodeLink; @@ -108,9 +109,11 @@ /* High level functions to create and use GPU materials */ -int GPU_material_from_blender(struct Material *ma); +int GPU_material_from_blender(struct Scene *scene, struct Material *ma); void GPU_material_free(GPUMaterial *material); +void GPU_materials_free(); + void GPU_material_bind(GPUMaterial *material, int lay); void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4]); void GPU_material_unbind(GPUMaterial *material); Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c =================================================================== --- branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-07-14 22:23:39 UTC (rev 15575) +++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-07-14 23:26:38 UTC (rev 15576) @@ -803,22 +803,34 @@ if (!shader) return; - /* create textures first, otherwise messes up multitexture state for - * following textures*/ - for (input=inputs->first; input; input=input->next) + GPU_shader_bind(shader); + + /* now bind the textures */ + for (input=inputs->first; input; input=input->next) { if (input->ima) input->tex = GPU_texture_from_blender(input->ima, input->iuser); - GPU_shader_bind(shader); - - /* pass dynamic inputs to opengl, others were already done */ - for (input=inputs->first; input; input=input->next) { if(input->ima || input->tex) { if(input->tex) { GPU_texture_bind(input->tex, input->texid); GPU_shader_uniform_texture(shader, input->shadername, input->tex); } } + } +} + +void GPU_pass_update_uniforms(GPUPass *pass) +{ + GPUInput *input; + GPUShader *shader = pass->shader; + ListBase *inputs = &pass->inputs; + + if (!shader) + return; + + /* pass dynamic inputs to opengl, others were already done */ + for (input=inputs->first; input; input=input->next) { + if(input->ima || input->tex); else if (input->arraysize) { GPU_shader_uniform_vector(shader, input->shadername, input->type, input->arraysize, input->dynamicvec); @@ -1380,6 +1392,8 @@ /* failed? */ if (!shader) { + memset(attribs, 0, sizeof(*attribs)); + memset(builtins, 0, sizeof(*builtins)); GPU_nodes_free(nodes); return NULL; } Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.h =================================================================== --- branches/apricot/source/blender/gpu/intern/gpu_codegen.h 2008-07-14 22:23:39 UTC (rev 15575) +++ branches/apricot/source/blender/gpu/intern/gpu_codegen.h 2008-07-14 23:26:38 UTC (rev 15576) @@ -72,6 +72,7 @@ struct GPUShader *GPU_pass_shader(GPUPass *pass); void GPU_pass_bind(GPUPass *pass); +void GPU_pass_update_uniforms(GPUPass *pass); void GPU_pass_unbind(GPUPass *pass); void GPU_pass_free(GPUPass *pass); Modified: branches/apricot/source/blender/gpu/intern/gpu_extensions.c =================================================================== --- branches/apricot/source/blender/gpu/intern/gpu_extensions.c 2008-07-14 22:23:39 UTC (rev 15575) +++ branches/apricot/source/blender/gpu/intern/gpu_extensions.c 2008-07-14 23:26:38 UTC (rev 15576) @@ -89,7 +89,7 @@ /* glewIsSupported("GL_VERSION_2_0") */ if (GLEW_ARB_multitexture) - glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &GG.maxtextures); + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures); if (GLEW_ATI_texture_float || GLEW_ARB_texture_float) { GG.halfformat = (GLEW_ATI_texture_float)? GL_RGBA_FLOAT16_ATI: GL_RGBA16F_ARB; } @@ -425,16 +425,20 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser) { GPUTexture *tex; - GLint w, h, border; - + GLint w, h, border, lastbindcode; + if(ima->gputexture) return ima->gputexture; + + glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode); if(!ima->bindcode) gpu_blender_texture_create(ima, iuser); - if(!ima->bindcode) + if(!ima->bindcode) { + glBindTexture(GL_TEXTURE_2D, lastbindcode); return NULL; + } tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = ima->bindcode; @@ -454,18 +458,17 @@ tex->h = tex->realh = 64; } else { - GPU_print_error("Blender Texture"); + glBindTexture(GL_TEXTURE_2D, tex->bindcode); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, &border); - glBindTexture(tex->target, tex->bindcode); - glGetTexLevelParameteriv(tex->target, 0, GL_TEXTURE_WIDTH, &w); - glGetTexLevelParameteriv(tex->target, 0, GL_TEXTURE_HEIGHT, &h); - glGetTexLevelParameteriv(tex->target, 0, GL_TEXTURE_BORDER, &border); - glBindTexture(tex->target, 0); - tex->w = tex->realw = w - border; tex->h = tex->realh = h - border; } + glBindTexture(GL_TEXTURE_2D, lastbindcode); + return tex; } @@ -501,10 +504,19 @@ void GPU_texture_bind(GPUTexture *tex, int number) { - GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + number); + GLenum arbnumber; + if (number >= GG.maxtextures) { + GPU_print_error("Not enough texture slots."); + return; + } + + if(number == -1) + return; + GPU_print_error("Pre Texture Bind"); + arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + number); if (number != 0) glActiveTextureARB(arbnumber); glBindTexture(tex->target, tex->bindcode); glEnable(tex->target); @@ -517,13 +529,19 @@ void GPU_texture_unbind(GPUTexture *tex) { - GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); + GLenum arbnumber; + if (tex->number >= GG.maxtextures) { + GPU_print_error("Not enough texture slots."); + return; + } + if(tex->number == -1) return; - + GPU_print_error("Pre Texture Unbind"); + arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); if (tex->number != 0) glActiveTextureARB(arbnumber); glBindTexture(tex->target, 0); glDisable(tex->target); @@ -804,16 +822,18 @@ fprintf(stderr, "GPUShader: %s error:\n", task); - c = code; - while ((c < end) && (pos = strchr(c, '\n'))) { - fprintf(stderr, "%2d ", line); - fwrite(c, (pos+1)-c, 1, stderr); - c = pos+1; - line++; + if(G.f & G_DEBUG) { + c = code; + while ((c < end) && (pos = strchr(c, '\n'))) { + fprintf(stderr, "%2d ", line); + fwrite(c, (pos+1)-c, 1, stderr); + c = pos+1; + line++; + } + + fprintf(stderr, "%s", c); } - fprintf(stderr, "%s", c); - fprintf(stderr, "%s\n", log); } @@ -958,6 +978,7 @@ MEM_freeN(shader); } + void GPU_shader_uniform_vector(GPUShader *shader, char *name, int length, int arraysize, float *value) { GLint location = glGetUniformLocationARB(shader->object, name); @@ -967,14 +988,12 @@ GPU_print_error("Pre Uniform Vector"); -#if 0 - if (length == 1) printf("%s %f\n", name, value[0]); + /*if (length == 1) printf("%s %f\n", name, value[0]); else if (length == 2) printf("%s %f %f\n", name, value[0], value[1]); else if (length == 3) { printf("%s ", name); printvecf("", value); } else if (length == 4) { printf("%s ", name); printquat("", value); } else if (length == 9) { printf("%s ", name); printmatrix3("", (float(*)[3])value); } - else if (length == 16) { printf("%s ", name); printmatrix4("", (float(*)[4])value); } -#endif + else if (length == 16) { printf("%s ", name); printmatrix4("", (float(*)[4])value); }*/ if (length == 1) glUniform1fvARB(location, arraysize, value); else if (length == 2) glUniform2fvARB(location, arraysize, value); @@ -988,11 +1007,22 @@ void GPU_shader_uniform_texture(GPUShader *shader, char *name, GPUTexture *tex) { - GLint location = glGetUniformLocationARB(shader->object, name); - GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); + GLint location; + GLenum arbnumber; + if (tex->number >= GG.maxtextures) { + GPU_print_error("Not enough texture slots."); + return; + } + + if(tex->number == -1) + return; + GPU_print_error("Pre Uniform Texture"); + location = glGetUniformLocationARB(shader->object, name); + arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); + if (tex->number != 0) glActiveTextureARB(arbnumber); glBindTexture(tex->target, tex->bindcode); glUniform1iARB(location, tex->number); Modified: branches/apricot/source/blender/gpu/intern/gpu_material.c =================================================================== --- branches/apricot/source/blender/gpu/intern/gpu_material.c 2008-07-14 22:23:39 UTC (rev 15575) +++ branches/apricot/source/blender/gpu/intern/gpu_material.c 2008-07-14 23:26:38 UTC (rev 15576) @@ -46,6 +46,7 @@ #include "BKE_colortools.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" +#include "BKE_main.h" #include "BKE_node.h" #include "BKE_texture.h" #include "BKE_utildefines.h" @@ -64,6 +65,7 @@ /* Structs */ struct GPUMaterial { + Scene *scene; Material *ma; /* for creating the material */ @@ -213,6 +215,7 @@ } GPU_pass_bind(material->pass); + //GPU_pass_update_uniforms(material->pass); /* handle alpha */ if(material->alpha) { @@ -260,6 +263,8 @@ Mat4MulMat4(lamp->dynimat, viewinv, lamp->imat); Mat4MulMat4(lamp->dynpersmat, viewinv, lamp->persmat); } + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs