Esempio n. 1
0
static int setActiveTexture (int c, GLfloat thisTransparency,  GLint *texUnit, GLint *texMode) 
{
	ttglobal tg = gglobal();

	/* which texture unit are we working on? */
    
	/* tie each fw_TextureX uniform into the correct texture unit */
    
	/* here we assign the texture unit to a specific number. NOTE: in the current code, this will ALWAYS
	 * be [0] = 0, [1] = 1; etc. */
	texUnit[c] = c;

#ifdef TEXVERBOSE
	if (getAppearanceProperties()->currentShaderProperties != NULL) {
		printf ("setActiveTexture %d, boundTextureStack is %d, sending to uniform %d\n",c,
			tg->RenderFuncs.boundTextureStack[c],
			getAppearanceProperties()->currentShaderProperties->TextureUnit[c]);
	} else {
		printf ("setActiveTexture %d, boundTextureStack is %d, sending to uniform [NULL--No Shader]\n",c,
			tg->RenderFuncs.boundTextureStack[c]);
	}
#endif
    
	/* is this a MultiTexture, or just a "normal" single texture?  When we
	 * bind_image, we store a pointer for the texture parameters. It is
	 * NULL, possibly different for MultiTextures */

	if (tg->RenderTextures.textureParameterStack[c].multitex_mode == INT_ID_UNDEFINED) {
        
		#ifdef TEXVERBOSE
		printf ("setActiveTexture - simple texture NOT a MultiTexture \n"); 
		#endif

		/* should we set the coloUr to 1,1,1,1 so that the material does not show
		 * through a RGB texture?? */
		/* only do for the first texture if MultiTexturing */
		if (c == 0) {
			#ifdef TEXVERBOSE
			printf ("setActiveTexture - firsttexture  \n"); 
			#endif
			texMode[c]= GL_MODULATE;
		} else {
			texMode[c]=GL_ADD;
		}

	} else {
	/* printf ("muititex source for %d is %d\n",c,tg->RenderTextures.textureParameterStack[c].multitex_source); */
		if (tg->RenderTextures.textureParameterStack[c].multitex_source != MTMODE_OFF) {
		} else {
			glDisable(GL_TEXTURE_2D); /* DISABLE_TEXTURES */
			return FALSE;
		}
	}


	PRINT_GL_ERROR_IF_ANY("");

	return TRUE;
}
Esempio n. 2
0
static bool setupShader() {
    ppRenderFuncs p = (ppRenderFuncs)gglobal()->RenderFuncs.prv;
    s_shader_capabilities_t *mysp = getAppearanceProperties()->currentShaderProperties;
    
	if (mysp != NULL) {
        

		/* if we had a shader compile problem, do not draw */
		if (!(mysp->compiledOK)) {
#ifdef RENDERVERBOSE
			printf ("shader compile error\n");
#endif
			return false;
		}
        
#ifdef RENDERVERBOSE
        printf ("we have Normals %d Vertices %d Colours %d TexCoords %d \n",
                mysp->Normals,
                mysp->Vertices,
                mysp->Colours,
                mysp->TexCoords);
		if (p->shaderNormalArray) printf ("p->shaderNormalArray TRUE\n"); else printf ("p->shaderNormalArray FALSE\n");        
        if (p->shaderVertexArray) printf ("shaderVertexArray TRUE\n"); else printf ("shaderVertexArray FALSE\n");
        if (p->shaderColourArray) printf ("shaderColourArray TRUE\n"); else printf ("shaderColourArray FALSE\n");
		if (p->shaderTextureArray) printf ("shaderTextureArray TRUE\n"); else printf ("shaderTextureArray FALSE\n");               
#endif
        
        /* send along lighting, material, other visible properties */
        sendMaterialsToShader(mysp);
        sendMatriciesToShader(mysp);
        
		if (mysp->Normals != -1) {
			if (p->shaderNormalArray) glEnableVertexAttribArray(mysp->Normals);
			else glDisableVertexAttribArray(mysp->Normals);
		}
        
		if (mysp->Vertices != -1) {
			if (p->shaderVertexArray) glEnableVertexAttribArray(mysp->Vertices);
			else glDisableVertexAttribArray(mysp->Vertices);
		}
        
		if (mysp->Colours != -1) {
			if (p->shaderColourArray) glEnableVertexAttribArray(mysp->Colours);
			else glDisableVertexAttribArray(mysp->Colours);
		}
        
		if (mysp->TexCoords != -1) {
			if (p->shaderTextureArray) glEnableVertexAttribArray(mysp->TexCoords);
			else glDisableVertexAttribArray(mysp->TexCoords);
		}
        
	}
    return true;
    
}
Esempio n. 3
0
void enableGlobalShader(s_shader_capabilities_t *myShader) {
    //ConsoleMessage ("enableGlobalShader, have myShader %d",myShader->myShaderProgram);
    if (myShader == NULL) {
        TURN_GLOBAL_SHADER_OFF; 
        return;
    };
    
    
    getAppearanceProperties()->currentShaderProperties = myShader;
	USE_SHADER(myShader->myShaderProgram);
}
Esempio n. 4
0
/* finished rendering thisshape. */
void turnGlobalShaderOff(void) {
	ppRenderFuncs p = (ppRenderFuncs)gglobal()->RenderFuncs.prv;

    /* get rid of the shader */
    getAppearanceProperties()->currentShaderProperties = NULL;
    USE_SHADER(0);

	/* set array booleans back to defaults */
	p->shaderNormalArray = TRUE;
	p->shaderVertexArray = TRUE;
	p->shaderColourArray = FALSE;
	p->shaderTextureArray = FALSE;
}
Esempio n. 5
0
OLDCODE#include "../scenegraph/Component_Shape.h"
OLDCODE
OLDCODE/* for OpenGL ES, we mimic the old glColor stuff from fixed functionality */
OLDCODE#ifdef GL_ES_VERSION_2_0
OLDCODEvoid glColor3d (double r, double g, double b) {
OLDCODE    float cols[3];
OLDCODE    cols[0] = (float)r;
OLDCODE    cols[1] = (float)g;
OLDCODE    cols[2] = (float)b;
OLDCODE    
OLDCODE//printf ("... active shader %d, for ",getAppearanceProperties()->currentShader);
OLDCODE//printf ("glColor3d %lf %lf %lf\n",r,g,b);
OLDCODE    s_shader_capabilities_t *me = getAppearanceProperties()->currentShaderProperties;
OLDCODE    
OLDCODE    if (me != NULL) {
OLDCODE        if (me->myMaterialColour != -1) {
OLDCODE            GLUNIFORM3FV(me->myMaterialColour,1,cols);
OLDCODE        } else {
Esempio n. 6
0
void sendClientStateToGPU(int enable, int cap) {
	ppRenderFuncs p = (ppRenderFuncs)gglobal()->RenderFuncs.prv;
	if (getAppearanceProperties()->currentShaderProperties != NULL) {
		switch (cap) {
			case GL_NORMAL_ARRAY:
				p->shaderNormalArray = enable;
				break;
			case GL_VERTEX_ARRAY:
				p->shaderVertexArray = enable;
				break;
			case GL_COLOR_ARRAY:
				p->shaderColourArray = enable;
				break;
			case GL_TEXTURE_COORD_ARRAY:
				p->shaderTextureArray = enable;
				break;

			default : {printf ("sendClientStateToGPU, unknown type in shader\n");}
		}
#ifdef RENDERVERBOSE
printf ("sendClientStateToGPU: getAppearanceProperties()->currentShaderProperties %p \n",getAppearanceProperties()->currentShaderProperties);
if (p->shaderNormalArray) printf ("enabling Normal\n"); else printf ("disabling Normal\n");
if (p->shaderVertexArray) printf ("enabling Vertex\n"); else printf ("disabling Vertex\n");
if (p->shaderColourArray) printf ("enabling Colour\n"); else printf ("disabling Colour\n");
if (p->shaderTextureArray) printf ("enabling Texture\n"); else printf ("disabling Texture\n");
#endif

	} else {
		#ifndef GL_ES_VERSION_2_0
			if (enable) glEnableClientState(cap);
			else glDisableClientState(cap);
		#else
			//printf ("sendClientStateToGPU - currentShaderProperties not set\n");
		#endif
	}
}
Esempio n. 7
0
static void passedInGenTex(struct textureVertexInfo *genTex) {
	int c;
	int i;
	GLint texUnit[MAX_MULTITEXTURE];
	GLint texMode[MAX_MULTITEXTURE];
	ttglobal tg = gglobal();

    s_shader_capabilities_t *me = getAppearanceProperties()->currentShaderProperties;

	#ifdef TEXVERBOSE
	printf ("passedInGenTex, using passed in genTex, textureStackTop %d\n",tg->RenderFuncs.textureStackTop);
        printf ("passedInGenTex, cubeFace %d\n",getAppearanceProperties()->cubeFace);
	#endif 

    /* simple shapes, like Boxes and Cones and Spheres will have pre-canned arrays */
	if (genTex->pre_canned_textureCoords != NULL) {
       // printf ("passedInGenTex, A\n");
		for (c=0; c<tg->RenderFuncs.textureStackTop; c++) {
            //printf ("passedInGenTex, c= %d\n",c);
			/* are we ok with this texture yet? */
			if (tg->RenderFuncs.boundTextureStack[c]!=0) {
                //printf ("passedInGenTex, B\n");
				if (setActiveTexture(c,getAppearanceProperties()->transparency,texUnit,texMode)) {
                    struct X3D_Node *tt = getThis_textureTransform();
                    //printf ("passedInGenTex, C\n");
                    if (tt!=NULL) do_textureTransform(tt,c);
                    SET_TEXTURE_UNIT_AND_BIND(getAppearanceProperties()->cubeFace,c,tg->RenderFuncs.boundTextureStack[c]);
                   
                    FW_GL_TEXCOORD_POINTER (2,GL_FLOAT,0,genTex->pre_canned_textureCoords);
                }
			}
}
	} else {
        //printf ("passedInGenTex, B\n");
		for (c=0; c<tg->RenderFuncs.textureStackTop; c++) {
            //printf ("passedInGenTex, c=%d\n",c);
			/* are we ok with this texture yet? */
			if (tg->RenderFuncs.boundTextureStack[c]!=0) {
                //printf ("passedInGenTex, C, boundTextureStack %d\n",tg->RenderFuncs.boundTextureStack[c]);
				if (setActiveTexture(c,getAppearanceProperties()->transparency,texUnit,texMode)) {
                    //printf ("passedInGenTex, going to bind to texture %d\n",tg->RenderFuncs.boundTextureStack[c]);
                    struct X3D_Node *tt = getThis_textureTransform();
                    if (tt!=NULL) do_textureTransform(tt,c);
                    SET_TEXTURE_UNIT_AND_BIND(getAppearanceProperties()->cubeFace,c,tg->RenderFuncs.boundTextureStack[c]);
                    
					FW_GL_TEXCOORD_POINTER (genTex->TC_size, 
						genTex->TC_type,
						genTex->TC_stride,
						genTex->TC_pointer);
				}
			}
		}

	}
    
    /* set up the selected shader for this texture(s) config */
	if (me != NULL) {
        //printf ("passedInGenTex, we have tts %d tc %d\n",tg->RenderFuncs.textureStackTop, me->textureCount);
        
        if (me->textureCount != -1) 
        glUniform1i(me->textureCount, tg->RenderFuncs.textureStackTop);
        
        
	    for (i=0; i<tg->RenderFuncs.textureStackTop; i++) {
        	//printf (" sending in i%d tu %d mode %d\n",i,i,tg->RenderTextures.textureParameterStack[i].multitex_mode);
            glUniform1i(me->TextureUnit[i],i);
            glUniform1i(me->TextureMode[i],tg->RenderTextures.textureParameterStack[i].multitex_mode);
        }
	#ifdef TEXVERBOSE
	} else {
		printf (" NOT sending in %d i+tu+mode because currentShaderProperties is NULL\n",tg->RenderFuncs.textureStackTop);
	#endif
	}

    
    
	PRINT_GL_ERROR_IF_ANY("");
}
Esempio n. 8
0
/* send in vertices, normals, etc, etc... to either a shader or via older opengl methods */
void sendAttribToGPU(int myType, int dataSize, int dataType, int normalized, int stride, float *pointer, char *file, int line){

    s_shader_capabilities_t *me = getAppearanceProperties()->currentShaderProperties;

#ifdef RENDERVERBOSE
printf ("sendAttribToGPU, getAppearanceProperties()->currentShaderProperties %p\n",getAppearanceProperties()->currentShaderProperties);
printf ("myType %d, dataSize %d, dataType %d, stride %d\n",myType,dataSize,dataType,stride);
	if (me != NULL) {
		switch (myType) {
			case FW_NORMAL_POINTER_TYPE:
				printf ("glVertexAttribPointer  Normals %d at %s:%d\n",me->Normals,file,line);
				break;
			case FW_VERTEX_POINTER_TYPE:
				printf ("glVertexAttribPointer  Vertexs %d at %s:%d\n",me->Vertices,file,line);
				break;
			case FW_COLOR_POINTER_TYPE:
				printf ("glVertexAttribPointer  Colours %d at %s:%d\n",me->Colours,file,line);
				break;
			case FW_TEXCOORD_POINTER_TYPE:
				printf ("glVertexAttribPointer  TexCoords %d at %s:%d\n",me->TexCoords,file,line);
				break;

			default : {printf ("sendAttribToGPU, unknown type in shader\n");}
		}
	}
#endif

	if (getAppearanceProperties()->currentShaderProperties != NULL) {
		switch (myType) {
			case FW_NORMAL_POINTER_TYPE:
			if (me->Normals != -1) {
				glEnableVertexAttribArray(me->Normals);
				glVertexAttribPointer(me->Normals, 3, dataType, normalized, stride, pointer);
			}
				break;
			case FW_VERTEX_POINTER_TYPE:
			if (me->Vertices != -1) {
				glEnableVertexAttribArray(me->Vertices);
				glVertexAttribPointer(me->Vertices, dataSize, dataType, normalized, stride, pointer);
			}
				break;
			case FW_COLOR_POINTER_TYPE:
			if (me->Colours != -1) {
				glEnableVertexAttribArray(me->Colours);
				glVertexAttribPointer(me->Colours, dataSize, dataType, normalized, stride, pointer);
			}
				break;
			case FW_TEXCOORD_POINTER_TYPE:
			if (me->TexCoords != -1) {
				glEnableVertexAttribArray(me->TexCoords);
				glVertexAttribPointer(me->TexCoords, dataSize, dataType, normalized, stride, pointer);
			}
				break;

			default : {printf ("sendAttribToGPU, unknown type in shader\n");}
		}

	/* not shaders; older style of rendering */
	} else {
		#ifndef GL_ES_VERSION_2_0
		switch (myType) {
			case FW_VERTEX_POINTER_TYPE:
				glVertexPointer(dataSize, dataType, stride, pointer); 
				break;
			case FW_NORMAL_POINTER_TYPE:
				glNormalPointer(dataType,stride,pointer);
				break;
			case FW_COLOR_POINTER_TYPE:
				glColorPointer(dataSize, dataType, stride, pointer); 
				break;
			case FW_TEXCOORD_POINTER_TYPE:
				glTexCoordPointer(dataSize, dataType, stride, pointer);
				break;
			default : {printf ("sendAttribToGPU, unknown type in shader\n");}
		}
		#else
		printf ("not shaders for pointers\n");
		#endif


	}
}