bool BlendChunk::operator == (const StateChunk &other) const
{
    BlendChunk const *tother = dynamic_cast<BlendChunk const*>(&other);

    if(!tother)
        return false;

    if(tother == this)
        return true;

    if(getSrcFactor()  != tother->getSrcFactor()  ||
       getDestFactor() != tother->getDestFactor() ||
       getEquation()   != tother->getEquation()   ||
       getColor()      != tother->getColor()      ||
       getAlphaFunc()  != tother->getAlphaFunc()  ||
       getAlphaValue() != tother->getAlphaValue()   )
        return false;

    return true;
}
Beispiel #2
0
void Material::load(const char *name) {
	blend = 0;
	alpha_test = 0;
	light_shader = NULL;
	ambient_shader = NULL;
	Parser *parser = new Parser(name);
	if(parser->get("blend")) {
		blend = 1;
		char s[1024];
		char d[1024];
		sscanf(parser->get("blend"),"%s %s",s,d);
		sfactor = getBlendFactor(s);
		dfactor = getBlendFactor(d);
	}
	if(parser->get("alpha_test")) {
		alpha_test = 1;
		char func[1024];
		sscanf(parser->get("alpha_test"),"%s %f",func,&alpha_ref);
		alpha_func = getAlphaFunc(func);
	}
	for(int i = 0; i < Shader::NUM_PARAMETERS; i++) {
		parameters[i] = vec4(0,0,0,0);
		char buf[1024];
		sprintf(buf,"parameter%d",i);
		if(parser->get(buf)) sscanf(parser->get(buf),"%f %f %f %f",&parameters[i].x,&parameters[i].y,&parameters[i].z,&parameters[i].w);
	}
	if(parser->get("light_shader")) {
		light_shader = Engine::loadShader(parser->get("light_shader"));
	}
	if(parser->get("ambient_shader")) {
		ambient_shader = Engine::loadShader(parser->get("ambient_shader"));
	}
	if(parser->get("shader")) {
		light_shader = ambient_shader = Engine::loadShader(parser->get("shader"));
	}
	for(int i = 0; i < Shader::NUM_TEXTURES; i++) {
		textures[i] = NULL;
		char buf[1024];
		sprintf(buf,"texture%d",i);
		char *s = parser->get(buf);
		if(s) {
			GLuint target = Texture::TEXTURE_2D;
			int flag = 0;
			int format = 0;
			int filter = 0;
			char name[1024];
			char *d = name;	// read name
			while(*s != '\0' && !strchr(" \t\n\r",*s)) *d++ = *s++;
			*d = '\0';
			d = buf;	// read flags
			while(*s != '\0' && *s != '\n' && strchr(" \t\r",*s)) s++;
			while(1) {
				if(*s == '\0' || strchr(" \t\n\r",*s)) {
					if(d == buf) break;
					*d = '\0';
					d = buf;
					while(*s != '\n' && *s != '\0' && strchr(" \t\r",*s)) s++;
					
					if(!strcmp(buf,"2D")) target = Texture::TEXTURE_2D;
					else if(!strcmp(buf,"RECT")) target = Texture::TEXTURE_RECT;
					else if(!strcmp(buf,"CUBE")) target = Texture::TEXTURE_CUBE;
					else if(!strcmp(buf,"3D")) target = Texture::TEXTURE_3D;
					
					else if(!strcmp(buf,"LUMINANCE")) format = Texture::LUMINANCE;
					else if(!strcmp(buf,"LUMINANCE_ALPHA")) format = Texture::LUMINANCE_ALPHA;
					else if(!strcmp(buf,"RGB")) format = Texture::RGB;
					else if(!strcmp(buf,"RGBA")) format = Texture::RGBA;
					
					else if(!strcmp(buf,"CLAMP")) flag |= Texture::CLAMP;
					else if(!strcmp(buf,"CLAMP_TO_EDGE")) flag |= Texture::CLAMP_TO_EDGE;
					
					else if(!strcmp(buf,"NEAREST")) filter = Texture::NEAREST;
					else if(!strcmp(buf,"LINEAR")) filter = Texture::LINEAR;
					else if(!strcmp(buf,"NEAREST_MIPMAP_NEAREST")) filter = Texture::NEAREST_MIPMAP_NEAREST;
					else if(!strcmp(buf,"LINEAR_MIPMAP_NEAREST")) filter = Texture::LINEAR_MIPMAP_NEAREST;
					else if(!strcmp(buf,"LINEAR_MIPMAP_LINEAR")) filter = Texture::LINEAR_MIPMAP_LINEAR;
					
					else if(!strcmp(buf,"ANISOTROPY_1")) flag |= Texture::ANISOTROPY_1;
					else if(!strcmp(buf,"ANISOTROPY_2")) flag |= Texture::ANISOTROPY_2;
					else if(!strcmp(buf,"ANISOTROPY_4")) flag |= Texture::ANISOTROPY_4;
					else if(!strcmp(buf,"ANISOTROPY_8")) flag |= Texture::ANISOTROPY_8;
					else if(!strcmp(buf,"ANISOTROPY_16")) flag |= Texture::ANISOTROPY_16;
					
					else fprintf(stderr,"Material::Material(): unknown texture%d flag \"%s\"\n",i,buf);
				} else *d++ = *s++;
			}
			textures[i] = Engine::loadTexture(name,target,flag | (format == 0 ? Texture::RGB : format) | (filter == 0 ? Engine::texture_filter : filter));
		} else {
			textures[i] = NULL;
		}
	}
	delete parser;
}