Пример #1
0
void ShaderManager::addShader(Shader *shader)
{
	if ( ! shader) 	return;

	for( Shader *s : shaders )
		if (shader == s )
			return;

	shaders.push_back(shader);	

	if ( ! getDefaultShader()) setDefaultShader(shader);
}
Пример #2
0
	// XXX Need a way to deal with blits with Camera/Lighting.
	void DisplayDeviceOpenGL::doBlitTexture(const TexturePtr& tex, int dstx, int dsty, int dstw, int dsth, float rotation, int srcx, int srcy, int srcw, int srch)
	{
		ASSERT_LOG(false, "DisplayDevice::doBlitTexture deprecated");
		ASSERT_LOG(!tex, "Texture passed in was not of expected type.");

		const float tx1 = float(srcx) / tex->width();
		const float ty1 = float(srcy) / tex->height();
		const float tx2 = srcw == 0 ? 1.0f : float(srcx + srcw) / tex->width();
		const float ty2 = srch == 0 ? 1.0f : float(srcy + srch) / tex->height();
		const float uv_coords[] = {
			tx1, ty1,
			tx2, ty1,
			tx1, ty2,
			tx2, ty2,
		};

		const float vx1 = float(dstx);
		const float vy1 = float(dsty);
		const float vx2 = float(dstx + dstw);
		const float vy2 = float(dsty + dsth);
		const float vtx_coords[] = {
			vx1, vy1,
			vx2, vy1,
			vx1, vy2,
			vx2, vy2,
		};

		// Apply blend mode from texture if there is any.
		BlendEquationScopeOGL be_scope(*tex);
		BlendModeScopeOGL bm_scope(*tex);

		glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3((vx1+vx2)/2.0f,(vy1+vy2)/2.0f,0.0f)) * glm::rotate(glm::mat4(1.0f), rotation, glm::vec3(0.0f,0.0f,1.0f)) * glm::translate(glm::mat4(1.0f), glm::vec3(-(vx1+vy1)/2.0f,-(vy1+vy1)/2.0f,0.0f));
		glm::mat4 mvp = glm::ortho(0.0f, 800.0f, 600.0f, 0.0f) * model;
		auto shader = OpenGL::ShaderProgram::defaultSystemShader();
		shader->makeActive();
		getDefaultShader()->setUniformsForTexture(tex);

		shader->setUniformValue(shader->getMvpUniform(), glm::value_ptr(mvp));
		shader->setUniformValue(shader->getColorUniform(), glm::value_ptr(glm::vec4(1.0f,1.0f,1.0f,1.0f)));
		// XXX the following line are only temporary, obviously.
		//shader->setUniformValue(shader->getUniform("discard"), 0);
		glEnableVertexAttribArray(shader->getVertexAttribute());
		glVertexAttribPointer(shader->getVertexAttribute(), 2, GL_FLOAT, GL_FALSE, 0, vtx_coords);
		glEnableVertexAttribArray(shader->getTexcoordAttribute());
		glVertexAttribPointer(shader->getTexcoordAttribute(), 2, GL_FLOAT, GL_FALSE, 0, uv_coords);

		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glDisableVertexAttribArray(shader->getTexcoordAttribute());
		glDisableVertexAttribArray(shader->getVertexAttribute());
	}
Пример #3
0
	IDraww(Shaders::ColorObject::Shader* shader = NULL) {
		if(shader == NULL) {
			shader = getDefaultShader();
		}
		shader = m_defaultshader;
	}