Beispiel #1
0
    TexturePtr GLGraphicFactory::create2DTexture(uint32 width, 
                                                 uint32 height, 
                                                 uint32 numMipmaps, 
                                                 ElementFormat format, 
                                                 const uint8* initialData,
                                                 uint32 flag) const {
        GLTexture2D* texture = new GLTexture2D();
        if(texture->create(width, height, numMipmaps, format, initialData)) {
            return TexturePtr(texture);
        }
		delete texture;
        return TexturePtr();
    }
	bool EtoileGLMeshRenderPassPlugin::loadFile(const std::string& filename)
	{
		if(filename.empty()) return false;
		std::string ext = File::getFileExtension(filename);
		std::string path = File::getFilePath(filename);
		TiXmlDocument doc(filename.c_str());
		if(!doc.LoadFile())
		{
			std::cout << "erreur while loading: " << filename<<std::endl;
			std::cout << "error #" << doc.ErrorId() << " : " << doc.ErrorDesc() << std::endl;
			return false;
		}
		this->getInputSockets().clear();
		this->addInputSocket(_pinputmesh);
		this->addInputSocket(_pinputmeshunit);
		if(_pview != NULL)
		{
			this->addInputSocket(_pview);
		}
		if(_pproj != NULL)
		{
			this->addInputSocket(_pproj);
		}
		if(_pviewproj != NULL)
		{
			this->addInputSocket(_pviewproj);
		}
		AABBWidget* aabbw = new AABBWidget();
		aabbw->bindPass(this);
		widget->addWidget(aabbw);
		TiXmlHandle hdl(&doc);

		TiXmlElement *elemRoot = hdl.FirstChildElement("Etoile").Element();
		while (elemRoot)
		{
			TiXmlElement *passElement = elemRoot->FirstChildElement("MeshPass");
			while (passElement)
			{
				std::string name = passElement->Attribute("name");
				this->getType()._description = name;
		
				int x;
				if(TIXML_NO_ATTRIBUTE!=passElement->QueryIntAttribute("x", &x))
				{
					this->_x = x;
				}
				int y;
				if(TIXML_NO_ATTRIBUTE!=passElement->QueryIntAttribute("y", &y))
				{
					this->_y = y;
				}
				int w;
				if(TIXML_NO_ATTRIBUTE!=passElement->QueryIntAttribute("w", &w))
				{
					this->_w = w;
				}
				int h;
				if(TIXML_NO_ATTRIBUTE!=passElement->QueryIntAttribute("h", &h))
				{
					this->_h = h;
				}
				initFBO();
				TiXmlElement *gpuElement = passElement->FirstChildElement("GPU");
				while (gpuElement)
				{
					const char* name = gpuElement->Attribute("name");
					std::map<ShaderType, std::string> files;
					TiXmlElement *vertexElement = gpuElement->FirstChildElement("vertex");
					if(vertexElement != NULL)
					{
						const char* file = vertexElement->Attribute("file");
						files[ShaderType::SHADERTYPE_VERTEX] = path + file;
					}
					TiXmlElement *fragElement = gpuElement->FirstChildElement("fragment");
					if(fragElement != NULL)
					{
						const char* file = fragElement->Attribute("file");
						files[SHADERTYPE_FRAGMENT] = path + file;
					}
					TiXmlElement *geometryElement = gpuElement->FirstChildElement("geometry");
					if(geometryElement != NULL)
					{
						const char* file = geometryElement->Attribute("file");
						files[SHADERTYPE_GEOMETRY] = path + file;
					}
					TiXmlElement *computeElement = gpuElement->FirstChildElement("compute");
					if(computeElement != NULL)
					{
						const char* file = computeElement->Attribute("file");
						files[SHADERTYPE_COMPUTE] = path + file;
					}
					TiXmlElement *tessCtrElement = gpuElement->FirstChildElement("tessctrl");
					if(tessCtrElement != NULL)
					{
						const char* file = tessCtrElement->Attribute("file");
						files[SHADERTYPE_TESSELLATION_CTRL] = path + file;
					}
					TiXmlElement *tessEvaElement = gpuElement->FirstChildElement("tesseval");
					if(tessEvaElement != NULL)
					{
						const char* file = tessEvaElement->Attribute("file");
						files[SHADERTYPE_TESSELLATION_EVAL] = path + file;
					}
					GLSLGpuProgram* glsl = new GLSLGpuProgram(name);
					glsl->loadShaderFiles(files);
					this->setCommonGpuProgram(glsl);
					GpuCompileWidget* gwidget = new GpuCompileWidget();
					gwidget->bindPass(this);
					widget->addWidget(gwidget);
					gpuElement = gpuElement->NextSiblingElement("GPU"); // iteration
				}

				TiXmlElement *outputsElement = passElement->FirstChildElement("Output");
				while (outputsElement)
				{
					std::string type = outputsElement->Attribute("type");
					std::string name = outputsElement->Attribute("name");
					if(type.compare("texture2d")==0)
					{
						TextureRenderTarget* tt = new TextureRenderTarget(name);
						GLTexture2D* t = new GLTexture2D(name);
						t->create(w,h,1);
						tt->set(t);
						this->addOutputSocket(tt);
					}

					outputsElement = outputsElement->NextSiblingElement("Output"); // iteration
				}

				TiXmlElement *inputsElement = passElement->FirstChildElement("Input");
				while (inputsElement)
				{
					std::string type = inputsElement->Attribute("type");
					std::string name = inputsElement->Attribute("name");
					if(type.compare("texture2d")==0)
					{
						EtoileMeshPassTextureInputSocket* in = new EtoileMeshPassTextureInputSocket(name);
						this->addInputSocket(in);
					}
					else if(type.compare("float")==0)
					{
						EtoileMeshPassFloatInputSocket* in = new EtoileMeshPassFloatInputSocket(name);
						in->setNode(this);
						//this->addInputSocket(in);
						FloatInputSocketWidget* socketwidget = new FloatInputSocketWidget(widget);
						float value;
						if(TIXML_NO_ATTRIBUTE!=inputsElement->QueryFloatAttribute("value", &value))
						{
							in->perform(&value);
						}
						socketwidget->bindParameter(in, value);
						widget->addWidget(socketwidget);
					}
					else if(type.compare("int")==0)
					{
						EtoileMeshPassIntInputSocket* in = new EtoileMeshPassIntInputSocket(name);
						in->setNode(this);
						//this->addInputSocket(in);
						IntInputSocketWidget* socketwidget = new IntInputSocketWidget(widget);
						int value = 0;
						if(TIXML_NO_ATTRIBUTE!=inputsElement->QueryIntAttribute("value", &value))
						{
							in->perform(&value);
						}
						socketwidget->bindParameter(in, value);
						widget->addWidget(socketwidget);
					}

					inputsElement = inputsElement->NextSiblingElement("Input"); // iteration
				}

				
				passElement = passElement->NextSiblingElement("MeshPass"); // iteration
			}

			elemRoot = elemRoot->NextSiblingElement("Etoile"); // iteration
		}
		
		return true;
	}