コード例 #1
0
ファイル: Clouds.cpp プロジェクト: Wumpf/cloudyclouds
void Clouds::samplerInit()
{
	// sampler
	glGenSamplers(1, &linearSampler_noMipMaps);
	glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

	glGenSamplers(1, &linearSampler_MipMaps);
	glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
}
コード例 #2
0
ファイル: GLTexture.cpp プロジェクト: pboechat/pga
			Texture::~Texture()
			{
				if (texture)
					glDeleteTextures(1, &texture);
				if (sampler)
					glGenSamplers(1, &sampler);
				PGA_Rendering_GL_checkError();
			}
コード例 #3
0
ファイル: Sampler.cpp プロジェクト: metiscus/derpy
Sampler::Sampler()
    : mSampler(0)
{
    glGenSamplers(1, &mSampler);
    glSamplerParameteri(mSampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(mSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glSamplerParameteri(mSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
}
コード例 #4
0
EXTERN_C_ENTER

JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBSamplerObjects_nglGenSamplers__IJ(JNIEnv *__env, jclass clazz, jint count, jlong samplersAddress) {
    glGenSamplersPROC glGenSamplers = (glGenSamplersPROC)tlsGetFunction(668);
    intptr_t samplers = (intptr_t)samplersAddress;
    UNUSED_PARAM(clazz)
    glGenSamplers(count, samplers);
}
コード例 #5
0
void CompositeFBOQuad::initFBOQuad(char * vertSource, char * fragSource, char *  name)
{
	printf("================================================================\n");
	printf("COMPOSITE FBO QUAD STATUS:\n");
	printf("Generating sampler...\n");
	// Create the sampler id.
	glGenSamplers(1, &sampler);
	
	// Load the vertex shader.
	vert.loadShader(vertSource, GL_VERTEX_SHADER, true);
	vert.printSource();
	
	// Load the fragment shader.
	frag.loadShader(fragSource, GL_FRAGMENT_SHADER, true);
	frag.printSource();

	// Link the two shaders into a shader program.
	shaderProgram.setName(name);
	shaderProgram.createProgram();
	shaderProgram.attachShaderToProgram(&vert);
	shaderProgram.attachShaderToProgram(&frag);
	shaderProgram.linkProgram();

	// Generate the vertex array that we will use for the quad.
	printf("Generating VAO...\n");
	glGenVertexArrays(1, &vertexArray);

	// Generate the vertex buffers that we will use.
	printf("Generating VBOs...\n");
	glGenBuffers(2, vboHandles);

	// Bind to our vertex array so that we can set up its buffers.
	printf("Binding to vertex array...\n");
	glBindVertexArray(vertexArray);

	// Set up buffer 0, which will be our vertex buffer.
	printf("Setting up vertex buffer...\n");
	glBindBuffer(GL_ARRAY_BUFFER, vboHandles[0]);
	// Since we call updateVerts() to actually populate the buffers, we simply declare
	// room for their data here.
	float floatsA[12];
	float floatsB[8];
	glBufferData(GL_ARRAY_BUFFER, 12*sizeof(float), floatsA, GL_DYNAMIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

	// Set up buffer 1, which will be our uv coordinate buffer.
	printf("Setting up UV buffer...\n");
	glBindBuffer(GL_ARRAY_BUFFER, vboHandles[1]);
	glBufferData(GL_ARRAY_BUFFER, 8*sizeof(float), floatsB, GL_DYNAMIC_DRAW);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);

	// Actually store the vertex data.
	updateVerts();
	printf("================================================================\n");
}
コード例 #6
0
bool initSampler()
{
	glGenSamplers(1, &SamplerName);
	glSamplerParameteri(SamplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glSamplerParameteri(SamplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	return glf::checkError("initSampler");
}
void GraphicsSubsystem::createSampler()
{
	glGenSamplers(1, &sampler);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
	//glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glSamplerParameteri( sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glSamplerParameteri( sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
}
コード例 #8
0
ファイル: Ground.cpp プロジェクト: hipblip/OutdoorScene
/*
	Loads a texture froma file to be applied to the terrain
	@param the path to the texture file
	@return whether or not the file was loaded correctly
*/
bool Ground::loadGroundTexture(string path) {
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	FIBITMAP* texture(0);
	fif = FreeImage_GetFileType(path.c_str(), 0);

	if (fif == FIF_UNKNOWN) { // Unknown file type
		//std::cout << "Unknown Filetype\n";
		fif = FreeImage_GetFIFFromFilename(path.c_str());
	}

	if (fif == FIF_UNKNOWN) { // Still unkown file type
		std::cout << "Unknown Filetype\n";
		return false;
	}

	if (FreeImage_FIFSupportsReading(fif)) { // is the file supported by free image?
		texture = FreeImage_Load(fif, path.c_str());
	}

	if (!texture) {
		std::cout << "This file type is not supported by FreeImage\n";
		return false;
	}

	BYTE* dataPointer = FreeImage_GetBits(texture);

	textureWidth = FreeImage_GetWidth(texture);
	textureHeight = FreeImage_GetHeight(texture);
	textureBPP = FreeImage_GetBPP(texture);

	glGenTextures(1, &textureID);
	glBindTexture(GL_TEXTURE_2D, textureID);
	
	int format = textureBPP == 24 ? GL_BGR : textureBPP == 8 ? GL_LUMINANCE : 0;
	int internalFormat = textureBPP == 24 ? GL_BGR : GL_DEPTH_COMPONENT;
		
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, format, GL_UNSIGNED_BYTE, dataPointer);

	glGenerateMipmap(GL_TEXTURE_2D);	

	FreeImage_Unload(texture);

	glGenSamplers(1, &samplerID);

	texturePath = path;

	// Tri linear filtering
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
	glGenerateMipmap(GL_TEXTURE_2D);

	return true;
}
コード例 #9
0
COGLSampler::COGLSampler(GLenum minFilter, GLenum magFilter, GLenum clampS, 
	GLenum clampT, std::string const& debugName)
	:COGLResource(COGL_SAMPLER, debugName)
{
	glGenSamplers(1, &m_Resource);

	glSamplerParameteri(m_Resource, GL_TEXTURE_MIN_FILTER, minFilter);
	glSamplerParameteri(m_Resource, GL_TEXTURE_MAG_FILTER, magFilter);
	glSamplerParameteri(m_Resource, GL_TEXTURE_WRAP_S, clampS);
	glSamplerParameteri(m_Resource, GL_TEXTURE_WRAP_T, clampT);
}
コード例 #10
0
//---------------------------------------------------------------------------//
  void TextureSamplerGL4::create( const ObjectName& rName, 
    const TextureSamplerDesc& rProperties )
  {
    destroy();

    const bool useMipmaps = rProperties.fMaxLod > 0.0f;

#if defined (FANCY_RENDERSYSTEM_USE_VALIDATION)
    // Some sanity-checks
    if (rProperties.minFiltering == SamplerFilterMode::ANISOTROPIC
      || rProperties.magFiltering == SamplerFilterMode::ANISOTROPIC)
    {
      ASSERT(rProperties.fMaxAnisotropy > 1.0f, 
        "Anisotropic filtering requested but maxAnisotropy level is 0");
    }

    if (!useMipmaps)
    {
      ASSERT(rProperties.minFiltering <= SamplerFilterMode::BILINEAR 
              && rProperties.magFiltering <= SamplerFilterMode::BILINEAR,
              "No mipmaps available but mipmap-filtering requested");
    }
#endif  // FANCY_RENDERSYSTEM_USE_VALIDATION

    const GLuint uglMinFiltering = Internal::getGLfilteringType(rProperties.minFiltering, useMipmaps);
    const GLuint uglMagFiltering = Internal::getGLfilteringType(rProperties.magFiltering, useMipmaps);
    const GLuint uglAddressModeX = Internal::getGLaddressMode(rProperties.addressModeX);
    const GLuint uglAddressModeY = Internal::getGLaddressMode(rProperties.addressModeY);
    const GLuint uglAddressModeZ = Internal::getGLaddressMode(rProperties.addressModeZ);
    const GLenum eglComparisonFunc = Adapter::toGLType(rProperties.comparisonFunc);
    const GLenum eglComparisonMode = (eglComparisonFunc == GL_ALWAYS || eglComparisonFunc == GL_NEVER) ?
                                       GL_NONE : GL_COMPARE_R_TO_TEXTURE;
    

    GLuint uSampler;
    glGenSamplers(1u, &uSampler);

    glSamplerParameteri(uSampler, GL_TEXTURE_MIN_FILTER, uglMinFiltering);
    glSamplerParameteri(uSampler, GL_TEXTURE_MAG_FILTER, uglMagFiltering);
    glSamplerParameteri(uSampler, GL_TEXTURE_WRAP_S, uglAddressModeX);
    glSamplerParameteri(uSampler, GL_TEXTURE_WRAP_T, uglAddressModeY);
    glSamplerParameteri(uSampler, GL_TEXTURE_WRAP_R, uglAddressModeZ);
    glSamplerParameteri(uSampler, GL_TEXTURE_COMPARE_FUNC, eglComparisonFunc);
    glSamplerParameteri(uSampler, GL_TEXTURE_COMPARE_MODE, eglComparisonMode);
    glSamplerParameterfv(uSampler, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(rProperties.borderColor));
    glSamplerParameterf(uSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, rProperties.fMaxAnisotropy);
    glSamplerParameterf(uSampler, GL_TEXTURE_LOD_BIAS, rProperties.fLodBias);
    glSamplerParameterf(uSampler, GL_TEXTURE_MIN_LOD, rProperties.fMinLod);
    glSamplerParameterf(uSampler, GL_TEXTURE_MAX_LOD, rProperties.fMaxLod);

    m_Name = rName;
    m_uHandleGL = uSampler;
    m_properties = rProperties;
  }
コード例 #11
0
void init(void)
{
	glClearColor(0.3, 0.3, 0.3, 1);

	glGenVertexArrays(1, &vao_quad);
	glBindVertexArray(vao_quad);
#define	N	30
	GLfloat	vertices[4][4] = {
		{ -0.90, -0.90, 0, N }, 
		{ 0.90, -0.90, N, N },
		{ -0.90, 0.90, 0, 0 },
		{ 0.90, 0.90, N, 0 },
	};
	glGenBuffers(1, &buf_quad);
	glBindBuffer(GL_ARRAY_BUFFER, buf_quad);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);


	GLuint h_prog = build_program_from_files("quad_tex_mipmap.vert", "quad_tex_mipmap.frag");

	glUseProgram(h_prog);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, BUFFER_OFFSET(0));
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, BUFFER_OFFSET(sizeof(GLfloat)*2));
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);

	glm::mat4	M = glm::rotate(glm::mat4(1.0f), -85.0f, glm::vec3(1.0f, 0.0f, 0.0f));
	glm::mat4	V = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -1.0f));
	glm::mat4	P = glm::perspective(45.0f, 1.0f, 0.1f, 5.0f);

	glUniformMatrix4fv(glGetUniformLocation(h_prog, "MVP"), 1, GL_FALSE, glm::value_ptr(P*V*M));
	glUniform4f(glGetUniformLocation(h_prog, "color"), 1, 1, .5, .5);
	glUniform1i(glGetUniformLocation(h_prog, "tex"), 4);

	glEnable(GL_CULL_FACE);

	load_textures();

	glGenSamplers(1, &sampler);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
//	glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
//	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
//	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

	glBindSampler(3, sampler);
	glBindSampler(4, sampler);

}
コード例 #12
0
ファイル: common.c プロジェクト: chemecse/piglit
GLuint new_sampler()
{
	GLuint sampler;

	glGenSamplers(1, &sampler);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	return sampler;
}
コード例 #13
0
ファイル: font.cpp プロジェクト: pavanky/forge
font_impl::font_impl()
    :   mIsFontLoaded(false), mTTFfile(""),
        mVBO(0), mProgram(0), mSampler(0)
{
    mProgram = initShaders(gFontVertShader, gFontFragShader);
    memset(mCharTextures, 0, NUM_CHARS);
    glGenSamplers(1, &mSampler);
    glSamplerParameteri(mSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glSamplerParameteri(mSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glSamplerParameteri(mSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(mSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
コード例 #14
0
/****************************
* LoadTexture - Loads the texture from file
****************************/
void Texture::LoadTexture(const char* file)
{
	glGenTextures(1,&textureID);
	glBindTexture(GL_TEXTURE_2D, textureID);

	textureID=SOIL_load_OGL_texture(file,SOIL_LOAD_AUTO,textureID,SOIL_FLAG_MIPMAPS);

	glGenSamplers(1,&samplerID);
	glBindSampler(ogl->textureSamplerID,samplerID);
	glSamplerParameteri(samplerID,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glSamplerParameteri(samplerID,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_LINEAR);
}
コード例 #15
0
	bool initSampler()
	{
		bool Validated(true);

		glGenSamplers(1, &SamplerName);
		glSamplerParameteri(SamplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glSamplerParameteri(SamplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

		return Validated;
	}
コード例 #16
0
ファイル: framebufferblit.c プロジェクト: aphogat/piglit
PIGLIT_GL_TEST_CONFIG_END

enum piglit_result
piglit_display(void)
{
	bool pass = true;
	GLuint tex, sampler, fb;
	const float tex_data[16] = {0, 1, 0, 0,
				    1, 0, 0, 0,
				    1, 0, 0, 0,
				    1, 0, 0, 0};
	const float *green = tex_data;

	glClearColor(0, 0, 1, 0);
	glClear(GL_COLOR_BUFFER_BIT);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0,
		     GL_RGBA, GL_FLOAT, tex_data);

	glGenFramebuffers(1, &fb);
	glBindFramebuffer(GL_FRAMEBUFFER, fb);

	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	assert(glGetError() == 0);

	glGenSamplers(1, &sampler);
	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindSampler(0, sampler);

	glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
	glBlitFramebuffer(0, 0, 1, 1,
			  0, 0, piglit_width, piglit_height,
			  GL_COLOR_BUFFER_BIT, GL_NEAREST);

	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
	piglit_present_results();

	glDeleteSamplers(1, &sampler);
	glDeleteTextures(1, &tex);
	glDeleteFramebuffers(1, &fb);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
コード例 #17
0
    void TextureManager::TImpl::ItlInitializeSamplerObjects()
    {
        glGenSamplers(1 , &m_pSamplerObjects[CLAMPED_NEAREST_FILTERING]);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_NEAREST_FILTERING], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_NEAREST_FILTERING], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_NEAREST_FILTERING], GL_TEXTURE_MIN_FILTER , GL_NEAREST);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_NEAREST_FILTERING], GL_TEXTURE_MAG_FILTER , GL_NEAREST);

        glGenSamplers(1 , &m_pSamplerObjects[CLAMPED_BILINEAR_FILTERING]);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_BILINEAR_FILTERING], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_BILINEAR_FILTERING], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_BILINEAR_FILTERING], GL_TEXTURE_MIN_FILTER , GL_LINEAR);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_BILINEAR_FILTERING], GL_TEXTURE_MAG_FILTER , GL_LINEAR);

        glGenSamplers(1 , &m_pSamplerObjects[CLAMPED_TRILINEAR_FILTERING]);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_TRILINEAR_FILTERING], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_TRILINEAR_FILTERING], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_TRILINEAR_FILTERING], GL_TEXTURE_MIN_FILTER , GL_LINEAR_MIPMAP_LINEAR);
        glSamplerParameteri(m_pSamplerObjects[CLAMPED_TRILINEAR_FILTERING], GL_TEXTURE_MAG_FILTER , GL_LINEAR);


    }
コード例 #18
0
ファイル: main.cpp プロジェクト: Nuos/textureMapsGL7
//设置并使用着色器
void initShader(void)
{
    shaderLoader.load("/Users/wistoneqqx/Documents/opengl/github/texture-maps-gl7/texture-maps/simpleShader.vert",
                      "/Users/wistoneqqx/Documents/opengl/github/texture-maps-gl7/texture-maps/simpleShader.frag");
    shaderLoader.bind();
    
    //定义两张纹理的采样器
    glGenSamplers(1,&g_Sampler1);
    glGenSamplers(1,&g_Sampler2);
    
    glSamplerParameteri(g_Sampler1, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(g_Sampler1, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
    glSamplerParameteri(g_Sampler2, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(g_Sampler2, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
    textureLocation1 = glGetUniformLocation(shaderLoader.getProgramID(), "u_texture1");
    textureLocation2 = glGetUniformLocation(shaderLoader.getProgramID(), "u_texture2");
    
    if(textureLocation1==-1 && textureLocation2==-1)
        printf("Get textureLocation error!\n");
}
コード例 #19
0
ファイル: SamplerCache.cpp プロジェクト: badkarma12/dolphin
SamplerCache::SamplerCache()
	: m_last_max_anisotropy()
{
	glGenSamplers(2, m_sampler_id);
	glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
コード例 #20
0
ファイル: Mesh.cpp プロジェクト: TrentSterling/jlEngine
	void Mesh::loadTexture(const std::string &path)
	{
		if(glIsTexture(m_meshTexture) == GL_FALSE)
			glGenTextures(1, &m_meshTexture);
		if(glIsSampler(m_meshSampler) == GL_FALSE)
			glGenSamplers(1, &m_meshSampler);

		// Setup sampler data
		glSamplerParameteri(m_meshSampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glSamplerParameteri(m_meshSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glSamplerParameteri(m_meshSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(m_meshSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

		SDL_Surface* surface = IMG_Load(path.c_str());

		GLint readFormat = GL_RGB;

		if(surface->format->BytesPerPixel == 4)
		{
			if(surface->format->Rmask == 0xFF)
				readFormat = GL_RGBA;
			else if(surface->format->Bmask == 0xFF)
				readFormat = GL_BGRA;
		}
		else if(surface->format->BytesPerPixel == 3)
		{
			if(surface->format->Rmask == 0xFF)
				readFormat = GL_RGB;
			else if(surface->format->Bmask == 0xFF)
				readFormat = GL_BGR;
		}
			
		if(surface->format->Rmask)

		GLfloat texDat[] =
		{
			1.f,1.f,1.f,1.f,
			0.f,1.f, 0.f, 1.f,
			1.f,1.f,1.f,1.f,
			0.f,1.f, 0.f, 1.f,
		};

		// Setup texture data
		glBindTexture(GL_TEXTURE_2D, m_meshTexture);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, readFormat, GL_UNSIGNED_BYTE, surface->pixels);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

		glBindTexture(GL_TEXTURE_2D, 0);
		SDL_FreeSurface(surface);
	}
コード例 #21
0
////////////////////////////////////////////////////////////////////////////////
// SoftShadowsRenderer::initRendering()
////////////////////////////////////////////////////////////////////////////////
void SoftShadowsRenderer::initRendering()
{
    GLint depthBits;
    glGetIntegerv(GL_DEPTH_BITS, &depthBits);
    LOGI("depth bits = %d\n", depthBits);

    // Setup the eye's view parameters
    initCamera(
        NvCameraXformType::MAIN,
        nv::vec3f(-0.644995f, 0.614183f, 0.660632f) * 1.5f, // position
        nv::vec3f(0.0f, 0.0f, 0.0f));                       // look at point

    // Setup the light's view parameters
    initCamera(
        NvCameraXformType::SECONDARY,
        nv::vec3f(3.57088f, 6.989f, 5.19698f) * 1.5f, // position
        nv::vec3f(0.0f, 0.0f, 0.0f));                 // look at point

    // Generate the samplers
    glGenSamplers(5, m_samplers);
    CHECK_GL_ERROR();
    for (GLuint unit = 0; unit < NumTextureUnits; ++unit)
    {
        glBindSampler(unit, m_samplers[unit]);
    }

    // Create resources
    createShadowMap();
    createGeometry();
    createTextures();
    createShaders();

    // Set states that don't change
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glDepthFunc(GL_LESS);
    glCullFace(GL_BACK);
    glDisable(GL_BLEND);

    glClearColor(
        m_backgroundColor.x,
        m_backgroundColor.y,
        m_backgroundColor.z,
        m_backgroundColor.w);
    glClearDepthf(1.0f);

    for (GLuint unit = 0; unit < NumTextureUnits; ++unit)
    {
        glBindSampler(unit, 0);
    }
}
コード例 #22
0
ファイル: cg-sampler-cache.c プロジェクト: rig-project/cglib
static cg_sampler_cache_entry_t *
_cg_sampler_cache_get_entry_gl(cg_sampler_cache_t *cache,
                               const cg_sampler_cache_entry_t *key)
{
    cg_sampler_cache_entry_t *entry;

    entry = c_hash_table_lookup(cache->hash_table_gl, key);

    if (entry == NULL) {
        cg_device_t *dev = cache->dev;

        entry = c_slice_dup(cg_sampler_cache_entry_t, key);

        if (_cg_has_private_feature(dev,
                                    CG_PRIVATE_FEATURE_SAMPLER_OBJECTS)) {
            GE(dev, glGenSamplers(1, &entry->sampler_object));

            GE(dev,
               glSamplerParameteri(entry->sampler_object,
                                   GL_TEXTURE_MIN_FILTER,
                                   entry->min_filter));
            GE(dev,
               glSamplerParameteri(entry->sampler_object,
                                   GL_TEXTURE_MAG_FILTER,
                                   entry->mag_filter));

            set_wrap_mode(dev,
                          entry->sampler_object,
                          GL_TEXTURE_WRAP_S,
                          entry->wrap_mode_s);
            set_wrap_mode(dev,
                          entry->sampler_object,
                          GL_TEXTURE_WRAP_T,
                          entry->wrap_mode_t);
            set_wrap_mode(dev,
                          entry->sampler_object,
                          GL_TEXTURE_WRAP_R,
                          entry->wrap_mode_p);
        } else {
            /* If sampler objects aren't supported then we'll invent a
               unique number so that pipelines can still compare the
               unique state just by comparing the sampler object
               numbers */
            entry->sampler_object = cache->next_fake_sampler_object_number++;
        }

        c_hash_table_insert(cache->hash_table_gl, entry, entry);
    }

    return entry;
}
コード例 #23
0
ファイル: OGLWindow.cpp プロジェクト: Snoop324/GFXiiFramework
void OGLWindow::InitOGLState()
{

	VSync(true);

	glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	//Initialise OGL shader
	m_shader = new OGLShaderProgram();
	m_skyBoxShader = new OGLShaderProgram();

	m_shader->CreateShaderProgram();
	m_shader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/basic.vert", SHADER_VERTEX);
	m_shader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/basic.frag", SHADER_FRAGMENT);

	m_shader->BindAttributeLocation( 0, "position" );
	m_shader->BindAttributeLocation( 1, "inNormal" );
	m_shader->BindAttributeLocation( 2, "inUV" );

	//shading skybox via shaders
	m_skyBoxShader->CreateShaderProgram();
	m_skyBoxShader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/skybox.vert", SHADER_VERTEX);
	m_skyBoxShader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/skybox.frag", SHADER_FRAGMENT);

	m_skyBoxShader->BindAttributeLocation(0, "position");
	m_skyBoxShader->BindAttributeLocation(1, "inNormal");
	m_skyBoxShader->BindAttributeLocation(2, "inUV");

	glBindFragDataLocation( m_shader->GetProgramHandle(), 0, "outFrag" );
	glBindFragDataLocation(m_skyBoxShader->GetProgramHandle(), 0, "outFrag");

	m_shader->BuildShaderProgram();
	m_shader->ActivateShaderProgram();

	m_skyBoxShader->BuildShaderProgram();
	m_shader->ActivateShaderProgram();
	

	glUniform1i( m_uniform_texture, 0 );

	//Create a texture sampler
	glGenSamplers( 1, (GLuint*)(&m_texDefaultSampler) );
	
	glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  
	glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);  
	glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_MIN_FILTER , GL_LINEAR);  
	glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_MAG_FILTER , GL_LINEAR);
}
コード例 #24
0
    static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
    {
        unsigned id;
        glGenSamplers(1, &id);
        glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.);

        v.push_back(createNearestSampler());
        e.push_back(GL_TEXTURE_2D);
        CreateSamplers<tp...>::exec(v, e);
    }
コード例 #25
0
ファイル: GLMaterial.hpp プロジェクト: YoungBot/Engine
	GLuint CreateSampler(GLenum min_filter, GLenum mag_filter, GLenum u_wrap, GLenum v_wrap)
	{
		GLuint sampler_id;
		glGenSamplers(1, &sampler_id);
		if (NULL == sampler_id) {
			return NULL;
		}
		glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filter);			// Default: GL_NEAREST_MIPMAP_LINEAR
		glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, mag_filter);			// Default: GL_LINEAR
		glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, u_wrap);					// Default: GL_REPEAT
		glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, v_wrap);					// Default: GL_REPEAT
		m_samplerID = sampler_id;
		return sampler_id;
	}
コード例 #26
0
void RGBAImage::sendToOpenGL(GLuint magFilter, GLuint minFilter, bool createMipMap)
{
	if (width <= 0 || height <= 0) return;

	glGenTextures(1, &textureId);
	glBindTexture(GL_TEXTURE_2D, textureId);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
	if (createMipMap) glGenerateMipmap(GL_TEXTURE_2D);

	glGenSamplers(1, &samplerId);
	glBindSampler(textureId, samplerId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
}
コード例 #27
0
void CTexture::CreateEmptyTexture(int a_iWidth, int a_iHeight, GLenum format)
{
	glGenTextures(1, &uiTexture);
	glBindTexture(GL_TEXTURE_2D, uiTexture);
	if(format == GL_RGBA || format == GL_BGRA)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, a_iWidth, a_iHeight, 0, format, GL_UNSIGNED_BYTE, NULL);
	// We must handle this because of internal format parameter
	else if(format == GL_RGB || format == GL_BGR)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, a_iWidth, a_iHeight, 0, format, GL_UNSIGNED_BYTE, NULL);
	else
		glTexImage2D(GL_TEXTURE_2D, 0, format, a_iWidth, a_iHeight, 0, format, GL_UNSIGNED_BYTE, NULL);
	
	glGenSamplers(1, &uiSampler);
}
コード例 #28
0
//-----------------------------------------------------------------------------------
int Renderer::CreateSampler(GLenum min_filter, //fragment counts for more than one texel, how does it shrink?
	GLenum magFilter, //more texels than fragments, how does it stretch?
	GLenum uWrap, //If u is < 0 or > 1, how does it behave?
	GLenum vWrap) //Same, but for v
{
	GLuint id;
	glGenSamplers(1, &id);

	glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, min_filter);
	glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, magFilter);
	glSamplerParameteri(id, GL_TEXTURE_WRAP_S, uWrap); //For some reason, OpenGL refers to UV's as ST's
	glSamplerParameteri(id, GL_TEXTURE_WRAP_T, vWrap);

	return id;
}
コード例 #29
0
ファイル: SamplerCache.cpp プロジェクト: badkarma12/dolphin
SamplerCache::Value& SamplerCache::GetEntry(const Params& params)
{
	auto& val = m_cache[params];
	if (!val.sampler_id)
	{
		// Sampler not found in cache, create it.
		glGenSamplers(1, &val.sampler_id);
		SetParameters(val.sampler_id, params);

		// TODO: Maybe kill old samplers if the cache gets huge. It doesn't seem to get huge though.
		//ERROR_LOG(VIDEO, "Sampler cache size is now %ld.", m_cache.size());
	}

	return val;
}
コード例 #30
0
void Application::makeSceneImplementation()
{
	_buildingMaterial.initialize();
	_roadMaterial.initialize();
	_groundMaterial.initialize();

	_buildingTexId = loadTexture( "../images/brick.jpg" );
	_roadTexId = loadTexture( "../images/road.jpg" );
	_groundTexId = loadTexture( "../images/ground.jpg" );

	
	//загрузка 3д-моделей
	_buildings = Mesh::makeBuildings(worker);
	_roads = Mesh::makeRoads( worker );
	_ground = Mesh::makeGround();
	
	//Инициализация значений переменных освщения
	_lightPos = glm::vec4( 20.0f, 20.0f, 0.5f, 1.0f );
	_ambientColor = glm::vec3( 0.2, 0.2, 0.2 );
	_diffuseColor = glm::vec3( 0.8, 0.8, 0.8 );
	_specularColor = glm::vec3( 0.5, 0.5, 0.5 );

	//Инициализация сэмплера - объекта, который хранит параметры чтения из текстуры
	glGenSamplers( 1, &_sampler );
	glSamplerParameteri( _sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glSamplerParameteri( _sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
	glSamplerParameteri( _sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
	glSamplerParameteri( _sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

	glGenSamplers( 1, &_repeatSampler );
	glSamplerParameteri( _repeatSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glSamplerParameteri( _repeatSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
	glSamplerParameterf( _repeatSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f );
	glSamplerParameteri( _repeatSampler, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glSamplerParameteri( _repeatSampler, GL_TEXTURE_WRAP_T, GL_REPEAT );
}