Exemple #1
0
ShaderSimpleDepth::ShaderSimpleDepth(bool doubleSided):
	m_with_color(false),
	m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)),
	m_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)),
	m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
	m_vboPos(NULL),
	m_vboColor(NULL)
{
	m_nameVS = "ShaderSimpleDepth_vs";
	m_nameFS = "ShaderSimpleDepth_fs";
//	m_nameGS = "ShaderSimpleDepth_gs";

	// get choose GL defines (2 or 3)
	// ans compile shaders
	std::string glxvert(*GLSLShader::DEFINES_GL);
	glxvert.append(vertexShaderText);
	std::string glxfrag(*GLSLShader::DEFINES_GL);
	if (doubleSided)
		glxfrag.append("#define DOUBLE_SIDED\n");
	glxfrag.append(fragmentShaderText);

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());

	// and get and fill uniforms
	getLocations();
	sendParams();
}
Exemple #2
0
unsigned int ShaderPhong::setAttributeColor(VBO* vbo)
{
    m_vboColor = vbo;
    if (!m_with_color)
    {
        m_with_color=true;
        // set the define and recompile shader
        std::string gl3vert(GLSLShader::defines_gl());
        gl3vert.append("#define WITH_COLOR 1\n");
        gl3vert.append(vertexShaderText);
        std::string gl3frag(GLSLShader::defines_gl());
        gl3frag.append("#define WITH_COLOR 1\n");
        gl3frag.append(fragmentShaderText);
        loadShadersFromMemory(gl3vert.c_str(), gl3frag.c_str());

        // and treat uniforms
        getLocations();
        sendParams();
    }
    // bind th VA with WBO
    bind();
    unsigned int id = bindVA_VBO("VertexColor", vbo);
    unbind();
    return id;
}
void ShaderSimpleFlat::setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos)
{
	m_ambiant = ambiant;
	m_diffuse = diffuse;
	m_lightPos = lightPos;
	sendParams();
}
Exemple #4
0
void Texture::onCreate(){
	//printf("Texture onCreate\n");
	glGenTextures(1, (GLuint *)&mID);
	sendParams();
	sendPixels();
	Graphics::error("creating texture");
}
void ShaderColorDarts::restoreUniformsAttribs()
{
	getLocations();
	sendParams();

	bind();
	bindVA_VBO("VertexPosition", m_vboPos);
	unbind();
}
Exemple #6
0
void ShaderPhong::setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos)
{
    m_ambiant = ambiant;
    m_diffuse = diffuse;
    m_specular = specular;
    m_shininess = shininess;
    m_lightPos = lightPos;
    sendParams();
}
Exemple #7
0
Texture2& Texture2::recreate(){
	destroy();
	glGenTextures(1, &mID); //printf("%i\n", mID);
	bind();
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, mFormat, mType, mPixels);
	glTexImage2D(GL_TEXTURE_2D, 0, mFormat, w, h, 0, mFormat, mType, mPixels);
	sendParams();
	return *this;
}
Exemple #8
0
void ShaderScalarField::restoreUniformsAttribs()
{
	getLocations();
	sendParams();

	bind();
	bindVA_VBO("VertexPosition", m_vboPos);
	bindVA_VBO("VertexScalar", m_vboScal);
	unbind();
}
void ShaderSimpleFlat::restoreUniformsAttribs()
{
	getLocations();
	sendParams();

	bind();
	bindVA_VBO("VertexPosition", m_vboPos);
	if (m_vboColor)
		bindVA_VBO("VertexColor", m_vboColor);

	unbind();
}
Exemple #10
0
void ShaderPhong::restoreUniformsAttribs()
{
    getLocations();
    sendParams();

    bind();
    bindVA_VBO("VertexPosition", m_vboPos);
    bindVA_VBO("VertexNormal", m_vboNormal);
    if (m_vboColor)
        bindVA_VBO("VertexColor", m_vboColor);

    unbind();
}
Exemple #11
0
ShaderPhong::ShaderPhong(bool withClipping, bool withEyePosition) :
    m_with_color(false),
    m_with_eyepos(withEyePosition),
    m_doubleSided(1),
    m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)),
    m_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)),
    m_specular(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f)),
    m_shininess(100.0f),
    m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
    m_backColor(0.0f,0.0f,0.0f,0.0f),
    m_vboPos(NULL),
    m_vboNormal(NULL),
    m_vboColor(NULL),
    m_planeClip(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f))
{
    std::string glxvert(GLSLShader::defines_gl());
    std::string glxfrag(GLSLShader::defines_gl());

    if (withClipping)
    {
        m_nameVS = "ShaderPhongClip_vs";
        m_nameFS = "ShaderPhongClip_fs";
        if (m_with_eyepos)
            glxvert.append("#define WITH_EYEPOSITION");
        glxvert.append(vertexShaderClipText);
        // Use double sided lighting if set
        //if (doubleSided)
        //	glxfrag.append("#define DOUBLE_SIDED\n");
        glxfrag.append(fragmentShaderClipText);
    }
    else
    {
        m_nameVS = "ShaderPhong_vs";
        m_nameFS = "ShaderPhong_fs";
        if (m_with_eyepos)
            glxvert.append("#define WITH_EYEPOSITION");
        glxvert.append(vertexShaderText);
        // Use double sided lighting if set
        //if (doubleSided)
        //	glxfrag.append("#define DOUBLE_SIDED\n");
        glxfrag.append(fragmentShaderText);
    }

    loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());

    // and get and fill uniforms
    getLocations();
    sendParams();
}
void CMPPathFollowingManager::RequestAttachEntityToPath( const SPathFollowingAttachToPathParameters& params )
{
	PathFollowers::const_iterator iter = m_PathFollowers.find(params.classId);
	if(iter != m_PathFollowers.end())
	{
		CRY_ASSERT_MESSAGE(params.pathIndex < m_Paths.size(), "CMPPathFollowingManager::RequestAttachEntityToPath - path index out of range");
		iter->second->OnAttachRequest(params, &m_Paths[params.pathIndex].path);
		if(gEnv->bServer)
		{
			SPathFollowingAttachToPathParameters sendParams(params);
			sendParams.forceSnap = true;
			g_pGame->GetGameRules()->GetGameObject()->InvokeRMI(CGameRules::ClPathFollowingAttachToPath(), params, eRMI_ToRemoteClients);
		}
	}
}
Exemple #13
0
ShaderScalarField::ShaderScalarField() :
	m_minValue(0.0f),
	m_maxValue(0.0f),
	m_expansion(0)
{
	std::string glxvert(*GLSLShader::DEFINES_GL);
	glxvert.append(vertexShaderText);

	std::string glxfrag(*GLSLShader::DEFINES_GL);
	glxfrag.append(fragmentShaderText);

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());

	// get and fill uniforms
	getLocations();
	sendParams();
}
Exemple #14
0
void Texture :: bind(int unit) {
	// ensure it is created:
	Graphics::error(id(), "before binding texture");
	validate(); 
	//Graphics::error(id(), "validate binding texture");
	sendParams(false);
	//Graphics::error(id(), "sendparams binding texture");
	sendPixels(false);
	//Graphics::error(id(), "sendpixels binding texture");
	
	// multitexturing:
	glActiveTexture(GL_TEXTURE0 + unit);
	//Graphics::error(id(), "active texture binding texture");

	// bind:
	glEnable(target());
	//Graphics::error(id(), "enable target binding texture");
	glBindTexture(target(), id());
	Graphics::error(id(), "binding texture");
}
Exemple #15
0
void ShaderPhong::unsetAttributeColor()
{
    m_vboColor = NULL;
    if (m_with_color)
    {
        m_with_color = false;
        // unbind the VA
        bind();
        unbindVA("VertexColor");
        unbind();
        // recompile shader
        std::string gl3vert(GLSLShader::defines_gl());
        gl3vert.append(vertexShaderText);
        std::string gl3frag(GLSLShader::defines_gl());
        gl3frag.append(fragmentShaderText);
        loadShadersFromMemory(gl3vert.c_str(), gl3frag.c_str());
        // and treat uniforms
        getLocations();
        sendParams();
    }
}
ShaderColorDarts::ShaderColorDarts() :
	m_lineWidth(0.01f),
	m_opacity(1.0f),
	m_planeClip(0.0f,0.0f,0.0f,0.0f)
{
	m_nameVS = "ShaderColorDarts_vs";
	m_nameFS = "ShaderColorDarts_fs";
	m_nameGS = "ShaderColorDarts_gs";

	std::string glxvert(GLSLShader::defines_gl());
	glxvert.append(vertexShaderText);

	std::string glxgeom = GLSLShader::defines_Geom("lines", "triangle_strip", 8);
	glxgeom.append(geometryShaderText);

	std::string glxfrag(GLSLShader::defines_gl());
	glxfrag.append(fragmentShaderText);

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES, GL_TRIANGLE_STRIP,8);

	// get and fill uniforms
	getLocations();
	sendParams();
}
Exemple #17
0
Texture2& Texture2::send(){

/*	void glTexSubImage2D(	GLenum target,
							GLint level,
							GLint xoffset, GLint yoffset,
							GLsizei width, GLsizei height,
							GLenum format, GLenum type,
							const GLvoid *pixels ) */
	sendParams();

	int tx = mUpdateRegion[0];
	int ty = mUpdateRegion[1];

	int tw = mUpdateRegion[2];
	if(tw < 0) tw = w+1+tw;
	int th = mUpdateRegion[3];
	if(th < 0) th = h+1+th;
	
	int bytesPerTexel = compsInFormat(mFormat) * bytesInType(mType);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, w);

	glTexSubImage2D(
		GL_TEXTURE_2D, 0,
		tx, ty,
		tw, th,
		mFormat, mType, (GLvoid*)((char*)mPixels + (ty*w + tx)*bytesPerTexel)
	);
	
	// change back to defaults
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

	return *this;
}
ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
	m_with_color(false),
	m_doubleSided(doubleSided),
	m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)),
	m_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)),
	m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
	m_backColor(0.0f,0.0f,0.0f,0.0f),
	m_vboPos(NULL),
	m_vboColor(NULL),
	m_planeClip(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f))
{
	std::string glxvert(GLSLShader::defines_gl());
	std::string glxfrag(GLSLShader::defines_gl());

	if (withClipping)
	{
		m_nameVS = "ShaderSimpleFlatClip_vs";
		m_nameFS = "ShaderSimpleFlatClip_fs";
		glxvert.append(vertexShaderClipText);
		glxfrag.append(fragmentShaderClipText);
	}
	else
	{
		m_nameVS = "ShaderSimpleFlat_vs";
		m_nameFS = "ShaderSimpleFlat_fs";
		// get choose GL defines (2 or 3)
		// ans compile shaders
		glxvert.append(vertexShaderText);
		glxfrag.append(fragmentShaderText);
	}

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
	// and get and fill uniforms
	getLocations();
	sendParams();
}
Exemple #19
0
void Texture :: submit(const void * pixels, uint32_t align) {
	Graphics::error(id(), "Texture::submit (initial)");
	validate();
	
	determineTarget();	// is this necessary? surely the target is already set!
	
	sendParams(false);
	
	glActiveTexture(GL_TEXTURE0);
	Graphics::error(id(), "Texture::submit (glActiveTexture)");
	glEnable(target());
	Graphics::error(id(), "Texture::submit (glEnable(texture target))");
	glBindTexture(target(), id());
	Graphics::error(id(), "Texture::submit (glBindTexture)");
	
	// set glPixelStore according to layout:
	glPixelStorei(GL_UNPACK_ALIGNMENT, mUnpack);
	Graphics::error(id(), "Texture::submit (glPixelStorei set)");
	
	// void glTexImage3D(
	//		GLenum target, GLint level, GLenum internalformat,
	//		GLsizei width, GLsizei height, GLsizei depth, 
	//		GLint border, GLenum format, GLenum type, const GLvoid *pixels
	// );
	
//	// internal format is important
//	// TODO: complete the derivation, probably do it elsewhere...
//	if(type() == Graphics::FLOAT || type() == Graphics::DOUBLE){
//		switch(numComponents()){
//			case 1: intFmt = GL_LUMINANCE32F_ARB; break;
//			case 2: intFmt = GL_LUMINANCE_ALPHA32F_ARB; break;
//			case 3: intFmt = GL_RGB32F_ARB; break;
//			case 4: intFmt = GL_RGBA32F_ARB; break;
//			default:;
//		}
//	} else {
//		// the old way - let the GPU decide:
//		intFmt = numComponents();
//	}

	int intFmt;

	// Use specified texel format, if defined
	if(mTexelFormat){
		intFmt = mTexelFormat;
	}
	
	// Derive internal texel format from texture data format.
	// By default, we can just use the texture data format. In cases where
	// there is no corresponding texel format, just hand in the number of
	// components.
	else{
		if(	format() == Graphics::RED ||
			format() == Graphics::GREEN ||
			format() == Graphics::BLUE
		){
			intFmt = 1;
		}
		else if(format() == Graphics::BGRA){
			intFmt = 4;
		}
		else{
			intFmt = format();
		}	
	}

	switch(mTarget){
		case GL_TEXTURE_1D:
			glTexImage1D(mTarget, 0, intFmt, width(), 0, format(), type(), pixels);
			break;
		case GL_TEXTURE_2D:
			glTexImage2D(mTarget, 0, intFmt, width(), height(), 0, format(), type(), pixels);
			break;
		case GL_TEXTURE_3D:
			glTexImage3D(mTarget, 0, intFmt, width(), height(), depth(), 0, format(), type(), pixels);
			break;
		default:
			printf("invalid texture target %d\n", mTarget);
	}
	Graphics::error(id(), "Texture::submit (glTexImage)");
	
	// set alignment back to default
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	Graphics::error(id(), "Texture::submit (glPixelStorei unset)");
	
//		// OpenGL may have changed the internal format to one it supports:
//		GLint format;
//		glGetTexLevelParameteriv(mTarget, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
//		if (format != mInternalFormat) {
//			printf("converted from %X to %X format\n", mInternalFormat, format);
//			mInternalFormat = format;
//		}

	//printf("submitted texture data %p\n", pixels);
	
	glDisable(target());
	glBindTexture(target(), 0);
	Graphics::error(id(), "Texture::submit (glBindTexture 0)");
}