/**
 * Main constructor.
 */
OpenGLRenderSystem::OpenGLRenderSystem() :
	_realised(false),
    _glProgramFactory(std::make_shared<GLProgramFactory>()),
	_currentShaderProgram(SHADER_PROGRAM_NONE),
	_time(0),
	m_lightsChanged(true),
	m_traverseRenderablesMutex(false)
{
	// For the static default rendersystem, the MaterialManager is not existent yet,
	// hence it will be attached in initialiseModule().
    if (module::ModuleRegistry::Instance().moduleExists(MODULE_SHADERSYSTEM))
	{
		_materialDefsLoaded = GlobalMaterialManager().signal_DefsLoaded().connect(
			sigc::mem_fun(*this, &OpenGLRenderSystem::realise));
		_materialDefsUnloaded = GlobalMaterialManager().signal_DefsUnloaded().connect(
			sigc::mem_fun(*this, &OpenGLRenderSystem::unrealise));

		if (GlobalMaterialManager().isRealised())
		{
			realise();
		}
	}

    // If the openGL module is already initialised and a shared context is created
    // trigger a call to extensionsInitialised().
    if (module::ModuleRegistry::Instance().moduleExists(MODULE_OPENGL) && 
        GlobalOpenGL().wxContextValid())
	{
        extensionsInitialised();
	}
}
void ShaderSystemInterface::foreachShader(shaders::ShaderVisitor& visitor)
{
	// Note: foreachShader only traverses the loaded materials, use a small adaptor to traverse all known
	ShaderNameToShaderWrapper adaptor(visitor);

	GlobalMaterialManager().foreachShaderName(boost::bind(&ShaderNameToShaderWrapper::visit, &adaptor, _1));
}
Example #3
0
void ShaderDefinitionView::update()
{
    // Find the shader
    MaterialPtr material = GlobalMaterialManager().getMaterialForName(_shader);

    if (material == NULL)
    {
        // Null-ify the contents
        gtk_label_set_markup(GTK_LABEL(_materialName), "");
        gtk_label_set_markup(GTK_LABEL(_filename), "");

        gtk_widget_set_sensitive(_view.getWidget(), FALSE);

        return;
    }

    // Add the shader and file name
    gtk_label_set_markup(GTK_LABEL(_materialName), ("<b>" + material->getName() + "</b>").c_str());
    gtk_label_set_markup(GTK_LABEL(_filename), (std::string("<b>") + material->getShaderFileName() + "</b>").c_str());

    gtk_widget_set_sensitive(_view.getWidget(), TRUE);

    // Surround the definition with curly braces, these are not included
    std::string definition = _shader + "\n{\n\r";
    definition += material->getDefinition();
    definition += "\n\r}";

    _view.setContents(definition);
}
void OpenGLRenderSystem::initialiseModule(const ApplicationContext& ctx)
{
	rMessage() << getName() << "::initialiseModule called." << std::endl;

	_materialDefsLoaded = GlobalMaterialManager().signal_DefsLoaded().connect(
		sigc::mem_fun(*this, &OpenGLRenderSystem::realise));
	_materialDefsUnloaded = GlobalMaterialManager().signal_DefsUnloaded().connect(
		sigc::mem_fun(*this, &OpenGLRenderSystem::unrealise));

	if (GlobalMaterialManager().isRealised())
	{
		realise();
	}

	// greebo: Don't realise the module yet, this must wait
	// until the shared GL context has been created (this
	// happens as soon as the first GL widget has been realised).
}
Example #5
0
void MediaBrowser::onRadiantShutdown()
{
	_tempParent->Destroy();

	GlobalMaterialManager().detach(*this);

	// Delete the singleton instance on shutdown
	getInstancePtr().reset();
}
Example #6
0
void MediaBrowser::_onLoadInTexView()
{
	// Use a TextureDirectoryLoader functor to search the directory. This
	// may throw an exception if cancelled by user.
	TextureDirectoryLoader loader(getSelectedName());

	try
	{
		GlobalMaterialManager().foreachShaderName(boost::bind(&TextureDirectoryLoader::visit, &loader, _1));
	}
	catch (wxutil::ModalProgressDialog::OperationAbortedException&)
	{
		// Ignore the error and return from the function normally
	}
}
Example #7
0
void MediaBrowser::init()
{
	// Create the widgets now
	getInstance().construct();

	// Check for pre-loading the textures
	if (registry::getValue<bool>(RKEY_MEDIA_BROWSER_PRELOAD))
	{
		getInstance().populate();
	}

	// Attach to the MaterialManager to get notified on unrealise/realise
	// events, in which case we're reloading the media tree
	GlobalMaterialManager().attach(getInstance());
}
void OpenGLRenderSystem::setShaderProgram(RenderSystem::ShaderProgram newProg)
{
    ShaderProgram oldProgram = _currentShaderProgram;

    if (oldProgram != newProg)
    {
		unrealise();
		GlobalMaterialManager().setLightingEnabled(
            newProg == SHADER_PROGRAM_INTERACTION
        );
    }

    _currentShaderProgram = newProg;

    if (oldProgram != newProg)
    {
        realise();
    }
}
Example #9
0
    // The worker function that will execute in the thread
    wxThread::ExitCode Entry()
    {
        // Create new treestoree
		_treeStore = new wxutil::TreeModel(_columns);
		_treeStore->SetHasDefaultCompare(false);
		
        ShaderNameFunctor functor(*_treeStore, _columns);
		GlobalMaterialManager().foreachShaderName(boost::bind(&ShaderNameFunctor::visit, &functor, _1));

		if (TestDestroy()) return static_cast<ExitCode>(0);

		// Sort the model while we're still in the worker thread
		_treeStore->SortModel(std::bind(&MediaBrowser::Populator::sortFunction, 
			this, std::placeholders::_1, std::placeholders::_2));

		if (!TestDestroy()) 
		{
			wxQueueEvent(_finishedHandler, new wxutil::TreeModel::PopulationFinishedEvent(_treeStore));
		}

		return static_cast<ExitCode>(0); 
    }
// Constructor. Copy the provided picoSurface_t structure into this object
RenderablePicoSurface::RenderablePicoSurface(picoSurface_t* surf,
											 const std::string& fExt)
: _shaderName(""),
  _dlRegular(0),
  _dlProgramVcol(0),
  _dlProgramNoVCol(0)
{
	// Get the shader from the picomodel struct. If this is a LWO model, use
	// the material name to select the shader, while for an ASE model the
	// bitmap path should be used.
	picoShader_t* shader = PicoGetSurfaceShader(surf);
	std::string rawName = "";

	if (shader != 0)
	{
		if (fExt == "lwo")
		{
			_shaderName = PicoGetShaderName(shader);
		}
		else if (fExt == "ase")
		{
			rawName = PicoGetShaderName(shader);
			std::string rawMapName = PicoGetShaderMapName(shader);
			_shaderName = cleanupShaderName(rawMapName);
		}
	}

	// If shader not found, fallback to alternative if available
	// _shaderName is empty if the ase material has no BITMAP
	// materialIsValid is false if _shaderName is not an existing shader
	if ((_shaderName.empty() || !GlobalMaterialManager().materialExists(_shaderName)) &&
		!rawName.empty())
	{
		_shaderName = cleanupShaderName(rawName);
	}

	// Capturing the shader happens later on when we have a RenderSystem reference

    // Get the number of vertices and indices, and reserve capacity in our
    // vectors in advance by populating them with empty structs.
    int nVerts = PicoGetSurfaceNumVertexes(surf);
    _nIndices = PicoGetSurfaceNumIndexes(surf);
    _vertices.resize(nVerts);
    _indices.resize(_nIndices);

    // Stream in the vertex data from the raw struct, expanding the local AABB
    // to include each vertex.
    for (int vNum = 0; vNum < nVerts; ++vNum) {

    	// Get the vertex position and colour
		Vertex3f vertex(PicoGetSurfaceXYZ(surf, vNum));

		// Expand the AABB to include this new vertex
    	_localAABB.includePoint(vertex);

    	_vertices[vNum].vertex = vertex;
    	_vertices[vNum].normal = Normal3f(PicoGetSurfaceNormal(surf, vNum));
    	_vertices[vNum].texcoord = TexCoord2f(PicoGetSurfaceST(surf, 0, vNum));
    	_vertices[vNum].colour =
    		getColourVector(PicoGetSurfaceColor(surf, 0, vNum));
    }

    // Stream in the index data
    picoIndex_t* ind = PicoGetSurfaceIndexes(surf, 0);
    for (unsigned int i = 0; i < _nIndices; i++)
    	_indices[i] = ind[i];

	// Calculate the tangent and bitangent vectors
	calculateTangents();

	// Construct the DLs
	createDisplayLists();
}
ScriptShader ShaderSystemInterface::getMaterialForName(const std::string& name) {
	return ScriptShader(GlobalMaterialManager().getMaterialForName(name));
}