예제 #1
0
void GLPatch::initializeBuffers(ShaderProgram & shaderProgram) {

    std::vector<BezierPatch> patchesv;

    ReadBezierPatches("data/teapot.data", patchesv);
    
    float patchesf[patchesv.size()][192];
    for (int i = 0; i < patchesv.size(); i++)
    {
       float patch[192];
       paramSurfaces(patchesv[i], patch); 
       m_numberOfPatches[i] = sizeof(patch) / sizeof(float); //i know this will be constant

       m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");

       GLuint m_Patch;
       m_Patches[i] = m_Patch;
       glGenBuffers(1, &m_Patch);
       glBindBuffer(GL_ARRAY_BUFFER, m_Patch);
       glBufferData(GL_ARRAY_BUFFER, sizeof(patch), patch, GL_STATIC_DRAW);
    }

	// glGenBuffers(1, &m_Patch);
	// glBindBuffer(GL_ARRAY_BUFFER, m_Patch);
	// glBufferData(GL_ARRAY_BUFFER, sizeof(patch), patch, GL_STATIC_DRAW);
    
    glm::vec3 Normal = glm::cross((patchesv[0][0][0] - patchesv[0][0][2]),(patchesv[0][0][2] - patchesv[0][3][3]));
    glm::vec3 N = glm::normalize(glm::vec3(Normal[0]+0.00001f,Normal[1]+0.000001f,Normal[2]+0.00001f));
    glUniform4f(glGetUniformLocation(shaderProgram.getProgram(), "uNormal"), N[0], N[0], N[2], 1.0);

	//Get a handle to the shader attribute aPosition and set it up:
	m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
	glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
예제 #2
0
static void renderSceneCB() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	triangleShaderProgram.useProgram();	

	glm::mat4 modelMatrix;
	modelMatrix = glm::translate(modelMatrix, glm::vec3(0.f, 0.0f, -105.0f));
	glUniformMatrix4fv(glGetUniformLocation(triangleShaderProgram.getProgram(), "uModelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
	
	glUniform3f(glGetUniformLocation(triangleShaderProgram.getProgram(), "uColour"), 0.0f, 1.0f, 0.0f);
	triangle.draw();

    glutSwapBuffers();
}
예제 #3
0
ShaderProgram* Manager::createShaderProgram(std::string vertexShaderPath, std::string fragmentShaderPath)
{
	ShaderProgram *shProg = new ShaderProgram();

	shProg->addVertexShader(vertexShaderPath.c_str());
	shProg->addFragmentShader(fragmentShaderPath.c_str());

	glBindAttribLocation(shProg->getProgram(), VERTICES, "in_Position");
	glBindAttribLocation(shProg->getProgram(), COLORS, "in_Color");
	glBindAttribLocation(shProg->getProgram(), NORMALS, "in_Normal");
	glBindAttribLocation(shProg->getProgram(), TEXTURE, "in_Texture");
	shProg->link();

	return shProg;
}
예제 #4
0
void GLTriangle::initializeBuffers(ShaderProgram & shaderProgram) {

	m_numberOfVerticesFront = 5;
	m_numberOfVerticesBack = 5;

	float front[] = { 
		0.0f, 0.0f, 0.0f,
		16.0f, 0.0f, 0.0f,
		16.0f, 10.0f, 0.0f,
		8.0f, 16.0f, 0.0f,
		0.0f, 10.0f, 0.0f
	};

	// float back[] = {
		// 0.0f, 0.0f, 30.0f,
		// 16.0f, 0.0f, 30.0f,
		// 16.0f, 10.0f, 30.0f,
		// 8.0f, 16.0f, 30.0f,
		// 0.0f, 10.0f, 30.0f
	// };

	m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");

	//Generate a vertex buffer object (m_VBO), and copy the array data (vertices) to it:
	// glGenBuffers(1, &m_BackVBO);
	// glBindBuffer(GL_ARRAY_BUFFER, m_BackVBO);
	// glBufferData(GL_ARRAY_BUFFER, sizeof(back), back, GL_STATIC_DRAW);
	// glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);

	glGenBuffers(1, &m_FrontVBO);
	glBindBuffer(GL_ARRAY_BUFFER, m_FrontVBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(front), front, GL_STATIC_DRAW);
	glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
예제 #5
0
static void intializeShadersAndGLObjects() {
	triangleShaderProgram.init(sVertexShader, sFragmentShader);
	triangle.initializeBuffers(triangleShaderProgram);

	triangleShaderProgram.useProgram();
	glm::mat4 projectionMatrix = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f); 
	glUniformMatrix4fv(glGetUniformLocation(triangleShaderProgram.getProgram(), "uProjectionMatrix"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
}
예제 #6
0
void GLCurve::initializeBuffers(ShaderProgram & shaderProgram) {

	m_numberOfCurves = 3;

	float curve[9] = { 
		-33.978017f, -34.985076f,  50.214926f,
		 84.192943f, -13.784394f, -50.214926f,
		-16.236910f,  83.754546f, -50.214926f
	};
    
    
	m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");

	//Generate a vertex buffer object (m_VBO), and copy the array data (vertices) to it:
	glGenBuffers(1, &m_Curve);
	glBindBuffer(GL_ARRAY_BUFFER, m_Curve);
	glBufferData(GL_ARRAY_BUFFER, sizeof(curve), curve, GL_STATIC_DRAW);

	//Get a handle to the shader attribute aPosition and set it up:
	m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");
	glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
예제 #7
0
void GLCurve::initializeBuffers(ShaderProgram & shaderProgram) {

    m_numberOfCurves = 4;

    float curve[] = {
        0.0f, 0.0f, 0.0f,
        4.0f, 5.0f, -5.0f,
        8.0f, -5.0f, 5.0f,
        12.0f, 0.0f, 0.0f
    };


    m_vertexPositionAttribute = glGetAttribLocation(shaderProgram.getProgram(), "aPosition");

    glGenBuffers(1, &m_Curve);
    glBindBuffer(GL_ARRAY_BUFFER, m_Curve);
    glBufferData(GL_ARRAY_BUFFER, m_numberOfCurves, curve, GL_STATIC_DRAW);
    glVertexAttribPointer(m_vertexPositionAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
예제 #8
0
void LightManager::initializeUniformLightBloc(ShaderProgram& aProgram, std::string aUniformLightBlocName)
{
	mLightUniformLightBlocName = aUniformLightBlocName;

	try
	{
		aProgram.loadUniformBloc(aUniformLightBlocName);
		mUniformBlockIndex = aProgram.getUniformBloc(aUniformLightBlocName);
		mUniformBlockBindingIndex = ShaderProgram::getNextGlobalUniformBlockBindingPointAvailable();
		glUniformBlockBinding(aProgram.getProgram(), mUniformBlockIndex, mUniformBlockBindingIndex);

		glGenBuffers(1, &mUniformBufferIndex);
		glBindBuffer(GL_UNIFORM_BUFFER, mUniformBufferIndex);

		//Init the buffer with zero everywhere
		size_t uniformBufferSize = sizeof(Light)*mMaxLights;
		char* zeroBuf = new char[uniformBufferSize]();

		glBufferData(GL_UNIFORM_BUFFER, uniformBufferSize, zeroBuf, GL_DYNAMIC_DRAW);

		delete[] zeroBuf;

		glBindBuffer(GL_UNIFORM_BUFFER, 0);

		glBindBufferRange(GL_UNIFORM_BUFFER, mUniformBlockBindingIndex, mUniformBufferIndex, 0, uniformBufferSize);
	}
	catch(ShaderProgramUniformNotLoadedException &e)
	{
		std::cerr << e.what() << std::endl;
	}
	catch(ShaderProgramUniformNotFoundException &e)
	{
		std::cerr << e.what() << std::endl;
	}

}
예제 #9
0
SharedBasicVarCase::IterateResult SharedBasicVarCase::iterate (void)
{
	const glw::Functions&		gl				= m_context.getRenderContext().getFunctions();
	const deUint32				program			= m_program->getProgram();
	Buffer						outputBuffer	(m_context.getRenderContext());
	const deUint32				outBlockNdx		= gl.getProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, "Result");
	const InterfaceBlockInfo	outBlockInfo	= getProgramInterfaceBlockInfo(gl, program, GL_SHADER_STORAGE_BLOCK, outBlockNdx);

	gl.useProgram(program);

	// Setup input values.
	{
		const int		numValues		= (int)product(m_workGroupSize);
		const int		valLoc			= gl.getUniformLocation(program, "u_val[0]");
		const int		refLoc			= gl.getUniformLocation(program, "u_ref[0]");
		const int		iterCountLoc	= gl.getUniformLocation(program, "u_numIters");
		const int		scalarSize		= getDataTypeScalarSize(m_basicType);

		if (isDataTypeFloatOrVec(m_basicType))
		{
			const int		maxInt			= m_precision == glu::PRECISION_LOWP ? 2 : 1024;
			const int		minInt			= -de::min(numValues/2, maxInt);
			vector<float>	values			(numValues*scalarSize);

			for (int ndx = 0; ndx < (int)values.size(); ndx++)
				values[ndx] = float(minInt + (ndx % (maxInt-minInt+1)));

			for (int uNdx = 0; uNdx < 2; uNdx++)
			{
				const int location = uNdx == 1 ? refLoc : valLoc;

				if (scalarSize == 1)		gl.uniform1fv(location, numValues, &values[0]);
				else if (scalarSize == 2)	gl.uniform2fv(location, numValues, &values[0]);
				else if (scalarSize == 3)	gl.uniform3fv(location, numValues, &values[0]);
				else if (scalarSize == 4)	gl.uniform4fv(location, numValues, &values[0]);
			}
		}
		else if (isDataTypeIntOrIVec(m_basicType))
		{
			const int		maxInt			= m_precision == glu::PRECISION_LOWP ? 64 : 1024;
			const int		minInt			= -de::min(numValues/2, maxInt);
			vector<int>		values			(numValues*scalarSize);

			for (int ndx = 0; ndx < (int)values.size(); ndx++)
				values[ndx] = minInt + (ndx % (maxInt-minInt+1));

			for (int uNdx = 0; uNdx < 2; uNdx++)
			{
				const int location = uNdx == 1 ? refLoc : valLoc;

				if (scalarSize == 1)		gl.uniform1iv(location, numValues, &values[0]);
				else if (scalarSize == 2)	gl.uniform2iv(location, numValues, &values[0]);
				else if (scalarSize == 3)	gl.uniform3iv(location, numValues, &values[0]);
				else if (scalarSize == 4)	gl.uniform4iv(location, numValues, &values[0]);
			}
		}
		else if (isDataTypeUintOrUVec(m_basicType))
		{
			const deUint32		maxInt		= m_precision == glu::PRECISION_LOWP ? 128 : 1024;
			vector<deUint32>	values		(numValues*scalarSize);

			for (int ndx = 0; ndx < (int)values.size(); ndx++)
				values[ndx] = ndx % (maxInt+1);

			for (int uNdx = 0; uNdx < 2; uNdx++)
			{
				const int location = uNdx == 1 ? refLoc : valLoc;

				if (scalarSize == 1)		gl.uniform1uiv(location, numValues, &values[0]);
				else if (scalarSize == 2)	gl.uniform2uiv(location, numValues, &values[0]);
				else if (scalarSize == 3)	gl.uniform3uiv(location, numValues, &values[0]);
				else if (scalarSize == 4)	gl.uniform4uiv(location, numValues, &values[0]);
			}
		}
		else if (isDataTypeBoolOrBVec(m_basicType))
		{
			de::Random		rnd				(0x324f);
			vector<int>		values			(numValues*scalarSize);

			for (int ndx = 0; ndx < (int)values.size(); ndx++)
				values[ndx] = rnd.getBool() ? 1 : 0;

			for (int uNdx = 0; uNdx < 2; uNdx++)
			{
				const int location = uNdx == 1 ? refLoc : valLoc;

				if (scalarSize == 1)		gl.uniform1iv(location, numValues, &values[0]);
				else if (scalarSize == 2)	gl.uniform2iv(location, numValues, &values[0]);
				else if (scalarSize == 3)	gl.uniform3iv(location, numValues, &values[0]);
				else if (scalarSize == 4)	gl.uniform4iv(location, numValues, &values[0]);
			}
		}
		else if (isDataTypeMatrix(m_basicType))
		{
			const int		maxInt			= m_precision == glu::PRECISION_LOWP ? 2 : 1024;
			const int		minInt			= -de::min(numValues/2, maxInt);
			vector<float>	values			(numValues*scalarSize);

			for (int ndx = 0; ndx < (int)values.size(); ndx++)
				values[ndx] = float(minInt + (ndx % (maxInt-minInt+1)));

			for (int uNdx = 0; uNdx < 2; uNdx++)
			{
				const int location = uNdx == 1 ? refLoc : valLoc;

				switch (m_basicType)
				{
					case TYPE_FLOAT_MAT2:	gl.uniformMatrix2fv  (location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT2X3:	gl.uniformMatrix2x3fv(location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT2X4:	gl.uniformMatrix2x4fv(location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT3X2:	gl.uniformMatrix3x2fv(location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT3:	gl.uniformMatrix3fv  (location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT3X4:	gl.uniformMatrix3x4fv(location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT4X2:	gl.uniformMatrix4x2fv(location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT4X3:	gl.uniformMatrix4x3fv(location, numValues, DE_FALSE, &values[0]);	break;
					case TYPE_FLOAT_MAT4:	gl.uniformMatrix4fv  (location, numValues, DE_FALSE, &values[0]);	break;
					default:
						DE_ASSERT(false);
				}
			}
		}

		gl.uniform1ui(iterCountLoc, product(m_workGroupSize));
		GLU_EXPECT_NO_ERROR(gl.getError(), "Input value setup failed");
	}

	// Setup output buffer.
	{
		vector<deUint8> emptyData(outBlockInfo.dataSize);
		std::fill(emptyData.begin(), emptyData.end(), 0);

		gl.bindBuffer(GL_SHADER_STORAGE_BUFFER, *outputBuffer);
		gl.bufferData(GL_SHADER_STORAGE_BUFFER, outBlockInfo.dataSize, &emptyData[0], GL_STATIC_READ);
		gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, *outputBuffer);
		GLU_EXPECT_NO_ERROR(gl.getError(), "Output buffer setup failed");
	}

	gl.dispatchCompute(1, 1, 1);

	// Read back and compare
	{
		const deUint32				numValues	= product(m_workGroupSize);
		const InterfaceVariableInfo	outVarInfo	= getProgramInterfaceVariableInfo(gl, program, GL_BUFFER_VARIABLE, outBlockInfo.activeVariables[0]);
		const void*					resPtr		= gl.mapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, outBlockInfo.dataSize, GL_MAP_READ_BIT);
		const int					maxErrMsg	= 10;
		int							numFailed	= 0;

		GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange()");
		TCU_CHECK(resPtr);

		for (deUint32 ndx = 0; ndx < numValues; ndx++)
		{
			const int resVal = *((const int*)((const deUint8*)resPtr + outVarInfo.offset + outVarInfo.arrayStride*ndx));

			if (resVal == 0)
			{
				if (numFailed < maxErrMsg)
					m_testCtx.getLog() << TestLog::Message << "ERROR: isOk[" << ndx << "] = " << resVal << " != true" << TestLog::EndMessage;
				else if (numFailed == maxErrMsg)
					m_testCtx.getLog() << TestLog::Message << "..." << TestLog::EndMessage;

				numFailed += 1;
			}
		}

		gl.unmapBuffer(GL_SHADER_STORAGE_BUFFER);
		GLU_EXPECT_NO_ERROR(gl.getError(), "glUnmapBuffer()");

		m_testCtx.getLog() << TestLog::Message << (numValues-numFailed) << " / " << numValues << " values passed" << TestLog::EndMessage;

		m_testCtx.setTestResult(numFailed == 0 ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
								numFailed == 0 ? "Pass"					: "Comparison failed");
	}

	return STOP;
}