bool initSampler()
	{
		glCreateSamplers(pipeline::MAX, &SamplerName[0]);

		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glSamplerParameterfv(SamplerName[pipeline::RENDER], GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
		glSamplerParameterf(SamplerName[pipeline::RENDER], GL_TEXTURE_MIN_LOD, -1000.f);
		glSamplerParameterf(SamplerName[pipeline::RENDER], GL_TEXTURE_MAX_LOD, 1000.f);
		glSamplerParameterf(SamplerName[pipeline::RENDER], GL_TEXTURE_LOD_BIAS, 0.0f);
		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glSamplerParameteri(SamplerName[pipeline::RENDER], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glSamplerParameterfv(SamplerName[pipeline::SPLASH], GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
		glSamplerParameterf(SamplerName[pipeline::SPLASH], GL_TEXTURE_MIN_LOD, -1000.f);
		glSamplerParameterf(SamplerName[pipeline::SPLASH], GL_TEXTURE_MAX_LOD, 1000.f);
		glSamplerParameterf(SamplerName[pipeline::SPLASH], GL_TEXTURE_LOD_BIAS, 0.0f);
		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glSamplerParameteri(SamplerName[pipeline::SPLASH], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

		return true;
	}
	bool initSampler()
	{
		glGenSamplers(1, &SamplerAName);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glSamplerParameterfv(SamplerAName, GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
		glSamplerParameterf(SamplerAName, GL_TEXTURE_MIN_LOD, -1000.f);
		glSamplerParameterf(SamplerAName, GL_TEXTURE_MAX_LOD, 1000.f);
		glSamplerParameterf(SamplerAName, GL_TEXTURE_LOD_BIAS, 3.0f);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glSamplerParameteri(SamplerAName, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

		glGenSamplers(1, &SamplerBName);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glSamplerParameterfv(SamplerBName, GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
		glSamplerParameterf(SamplerBName, GL_TEXTURE_MIN_LOD, -1000.f);
		glSamplerParameterf(SamplerBName, GL_TEXTURE_MAX_LOD, 1000.f);
		glSamplerParameterf(SamplerBName, GL_TEXTURE_LOD_BIAS, 3.0f);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glSamplerParameteri(SamplerBName, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

		return true;
	}
	bool initSampler()
	{
		glGenSamplers(sampler::MAX, &SamplerName[0]);

		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glSamplerParameterfv(SamplerName[sampler::SEAMLESS], GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
		glSamplerParameterf(SamplerName[sampler::SEAMLESS], GL_TEXTURE_MIN_LOD, -1000.f);
		glSamplerParameterf(SamplerName[sampler::SEAMLESS], GL_TEXTURE_MAX_LOD, 1000.f);
		glSamplerParameterf(SamplerName[sampler::SEAMLESS], GL_TEXTURE_LOD_BIAS, 0.0f);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
		glSamplerParameterf(SamplerName[sampler::SEAMLESS], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
		glSamplerParameteri(SamplerName[sampler::SEAMLESS], GL_TEXTURE_CUBE_MAP_SEAMLESS, GL_TRUE);

		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glSamplerParameterfv(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
		glSamplerParameterf(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_MIN_LOD, -1000.f);
		glSamplerParameterf(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_MAX_LOD, 1000.f);
		glSamplerParameterf(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_LOD_BIAS, 0.0f);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
		glSamplerParameterf(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
		glSamplerParameteri(SamplerName[sampler::NON_SEAMLESS], GL_TEXTURE_CUBE_MAP_SEAMLESS, GL_FALSE);

		return true;
	}
Beispiel #4
0
void GL::Sampler::setSamplingState(TextureTarget target, const SamplingState& state) {
    if (state.isParameterSet(SamplingState::Parameter::WrapS))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_WRAP_S, GLint(state.wrap.s));

    if (state.isParameterSet(SamplingState::Parameter::WrapT))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_WRAP_T, GLint(state.wrap.t));

    if (state.isParameterSet(SamplingState::Parameter::WrapR))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_WRAP_R, GLint(state.wrap.r));

    if (state.isParameterSet(SamplingState::Parameter::MinFilter))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_MIN_FILTER, GLint(state.filter.min));

    if (state.isParameterSet(SamplingState::Parameter::MagFilter))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_MAG_FILTER, GLint(state.filter.mag));

    if (state.isParameterSet(SamplingState::Parameter::BorderColor))
        glSamplerParameterfv(GLenum(target), GL_TEXTURE_BORDER_COLOR, &(state.borderColor.r));

    if (state.isParameterSet(SamplingState::Parameter::MinLOD))
        glSamplerParameterf(GLenum(target), GL_TEXTURE_MIN_LOD, state.LOD.min);

    if (state.isParameterSet(SamplingState::Parameter::MaxLOD))
        glSamplerParameterf(GLenum(target), GL_TEXTURE_MAX_LOD, state.LOD.max);

    if (state.isParameterSet(SamplingState::Parameter::LODbias))
        glSamplerParameterf(GLenum(target), GL_TEXTURE_LOD_BIAS, state.LOD.bias);

    if (state.isParameterSet(SamplingState::Parameter::CompareMode))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_COMPARE_MODE, GLint(state.compare.mode));

    if (state.isParameterSet(SamplingState::Parameter::CompareFunc))
        glSamplerParameteri(GLenum(target), GL_TEXTURE_COMPARE_FUNC, GLint(state.compare.func));
}
OpenGLSamplerState::OpenGLSamplerState( const SamplerStateDesc& desc )
	: SamplerState(desc),
	  mSamplerOGL(0)
{
	glGenSamplers(1, &mSamplerOGL);

	glSamplerParameteri(mSamplerOGL, GL_TEXTURE_WRAP_S, OpenGLMapping::Mapping(desc.AddressU));
	glSamplerParameteri(mSamplerOGL, GL_TEXTURE_WRAP_T, OpenGLMapping::Mapping(desc.AddressV));
	glSamplerParameteri(mSamplerOGL, GL_TEXTURE_WRAP_R, OpenGLMapping::Mapping(desc.AddressW));

	GLenum min, mag;
	OpenGLMapping::Mapping( min, mag, desc.Filter );
	glSamplerParameteri(mSamplerOGL, GL_TEXTURE_MAG_FILTER, mag);
	glSamplerParameteri(mSamplerOGL, GL_TEXTURE_MIN_FILTER, min);

	glSamplerParameterf(mSamplerOGL, GL_TEXTURE_MAX_ANISOTROPY_EXT, desc.MaxAnisotropy);

	glSamplerParameterf(mSamplerOGL, GL_TEXTURE_MIN_LOD, desc.MinLOD);
	glSamplerParameterf(mSamplerOGL, GL_TEXTURE_MAX_LOD, desc.MaxLOD);
	glSamplerParameterf(mSamplerOGL, GL_TEXTURE_LOD_BIAS , desc.MipLODBias);

	glSamplerParameterfv(mSamplerOGL, GL_TEXTURE_BORDER_COLOR, desc.BorderColor());

	if (desc.CompareSampler)
	{
		// Use GL_COMPARE_REF_TO_TEXTURE
		glSamplerParameteri(mSamplerOGL, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
		glSamplerParameteri(mSamplerOGL, GL_TEXTURE_COMPARE_FUNC, OpenGLMapping::Mapping(desc.ComparisonFunc));
	}

	OGL_ERROR_CHECK();
}
GLuint glCreateSamplerGTC(GLenum mag, GLenum min, GLenum mip, GLenum wrap, GLfloat borderColor[4], GLenum compare)
{
	assert(mag == GL_LINEAR || mag == GL_NEAREST);
	assert(min == GL_LINEAR || min == GL_NEAREST);
	assert(mip == GL_LINEAR || mip == GL_NEAREST);

	GLuint sampler = 0;
	glCreateSamplers(1, &sampler);

	GLint minFilter = GL_NONE;
	if (min == GL_LINEAR)
		minFilter = mip == GL_LINEAR ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST;
	else
		minFilter = mip == GL_LINEAR ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST;

	glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, minFilter);
	glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, mag);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, wrap);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, wrap);
	glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, wrap);
	glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
	glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, compare == GL_NONE ? GL_NONE : GL_COMPARE_R_TO_TEXTURE);
	glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, compare != GL_NONE ? compare : GL_LEQUAL);

	return sampler;
}
bool initSampler()
{
	glGenSamplers(viewport::MAX, &SamplerName[0]);

	for(std::size_t i = 0; i < viewport::MAX; ++i)
	{
		glSamplerParameteri(SamplerName[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glSamplerParameteri(SamplerName[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glm::vec4 BorderColor(0.0f, 0.5f, 1.0f, 1.0f);
		glSamplerParameterfv(SamplerName[i], GL_TEXTURE_BORDER_COLOR, &BorderColor[0]);
	}

	glSamplerParameteri(SamplerName[viewport::VIEWPORT0], GL_TEXTURE_WRAP_S, GL_REPEAT);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT3], GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT4], GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
	if(glf::checkExtension("GL_EXT_texture_mirror_clamp"))
		glSamplerParameteri(SamplerName[viewport::VIEWPORT5], GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_BORDER_EXT);
	else
		glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);

	glSamplerParameteri(SamplerName[viewport::VIEWPORT0], GL_TEXTURE_WRAP_T, GL_REPEAT);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT3], GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
	glSamplerParameteri(SamplerName[viewport::VIEWPORT4], GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_EDGE);
	if(glf::checkExtension("GL_EXT_texture_mirror_clamp"))
		glSamplerParameteri(SamplerName[viewport::VIEWPORT5], GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_BORDER_EXT);
	else
		glSamplerParameteri(SamplerName[viewport::VIEWPORT2], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

	return glf::checkError("initSampler");
}
//---------------------------------------------------------------------------//
  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;
  }
bool initSampler()
{
	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);
	glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
	glSamplerParameterfv(SamplerName, GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]);
	glSamplerParameterf(SamplerName, GL_TEXTURE_MIN_LOD, -1000.f);
	glSamplerParameterf(SamplerName, GL_TEXTURE_MAX_LOD, 1000.f);
	glSamplerParameterf(SamplerName, GL_TEXTURE_LOD_BIAS, 0.0f);
	glSamplerParameteri(SamplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
	glSamplerParameteri(SamplerName, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

	return glf::checkError("initSampler");
}
Beispiel #10
0
	//Apply sampler state settings
	void sampler_state::apply(rsx::fragment_texture& tex)
	{
		const f32 border_color = (f32)tex.border_color() / 255;
		const f32 border_color_array[] = { border_color, border_color, border_color, border_color };

		glSamplerParameteri(samplerHandle, GL_TEXTURE_WRAP_S, wrap_mode(tex.wrap_s()));
		glSamplerParameteri(samplerHandle, GL_TEXTURE_WRAP_T, wrap_mode(tex.wrap_t()));
		glSamplerParameteri(samplerHandle, GL_TEXTURE_WRAP_R, wrap_mode(tex.wrap_r()));
		glSamplerParameterfv(samplerHandle, GL_TEXTURE_BORDER_COLOR, border_color_array);

		if (tex.get_exact_mipmap_count() <= 1)
		{
			GLint min_filter = tex_min_filter(tex.min_filter());

			if (min_filter != GL_LINEAR && min_filter != GL_NEAREST)
			{
				switch (min_filter)
				{
				case GL_NEAREST_MIPMAP_NEAREST:
				case GL_NEAREST_MIPMAP_LINEAR:
					min_filter = GL_NEAREST; break;
				case GL_LINEAR_MIPMAP_NEAREST:
				case GL_LINEAR_MIPMAP_LINEAR:
					min_filter = GL_LINEAR; break;
				default:
					LOG_ERROR(RSX, "No mipmap fallback defined for rsx_min_filter = 0x%X", (u32)tex.min_filter());
					min_filter = GL_NEAREST;
				}
			}

			glSamplerParameteri(samplerHandle, GL_TEXTURE_MIN_FILTER, min_filter);
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_LOD_BIAS, 0.);
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MIN_LOD, 0);
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MAX_LOD, 0);
		}
		else
		{
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MIN_FILTER, tex_min_filter(tex.min_filter()));
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_LOD_BIAS, tex.bias());
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MIN_LOD, (tex.min_lod() >> 8));
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MAX_LOD, (tex.max_lod() >> 8));
		}

		glSamplerParameteri(samplerHandle,  GL_TEXTURE_MAG_FILTER, tex_mag_filter(tex.mag_filter()));
		glSamplerParameteri(samplerHandle,  GL_TEXTURE_MAX_ANISOTROPY_EXT, ::gl::max_aniso(tex.max_aniso()));
	}
Beispiel #11
0
static void wined3d_sampler_init(struct wined3d_sampler *sampler, struct wined3d_device *device,
        const struct wined3d_sampler_desc *desc, void *parent)
{
    const struct wined3d_gl_info *gl_info;
    struct wined3d_context *context;

    sampler->refcount = 1;
    sampler->device = device;
    sampler->parent = parent;
    sampler->desc = *desc;

    context = context_acquire(device, NULL);
    gl_info = context->gl_info;

    GL_EXTCALL(glGenSamplers(1, &sampler->name));
    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_S,
            gl_info->wrap_lookup[desc->address_u - WINED3D_TADDRESS_WRAP]));
    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_T,
            gl_info->wrap_lookup[desc->address_v - WINED3D_TADDRESS_WRAP]));
    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_R,
            gl_info->wrap_lookup[desc->address_w - WINED3D_TADDRESS_WRAP]));
    GL_EXTCALL(glSamplerParameterfv(sampler->name, GL_TEXTURE_BORDER_COLOR, &desc->border_color[0]));
    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MAG_FILTER,
            wined3d_gl_mag_filter(desc->mag_filter)));
    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MIN_FILTER,
            wined3d_gl_min_mip_filter(desc->min_filter, desc->mip_filter)));
    GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_LOD_BIAS, desc->lod_bias));
    GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_MIN_LOD, desc->min_lod));
    GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_MAX_LOD, desc->max_lod));
    if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
        GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MAX_ANISOTROPY_EXT, desc->max_anisotropy));
    if (desc->compare)
        GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE));
    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_COMPARE_FUNC,
            wined3d_gl_compare_func(desc->comparison_func)));
    if ((context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
            && gl_info->supported[EXT_TEXTURE_SRGB_DECODE] && !desc->srgb_decode)
        GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT));
    checkGLcall("sampler creation");

    TRACE("Created sampler %u.\n", sampler->name);

    context_release(context);
}
bool initSampler()
{
	glGenSamplers(viewport::MAX, SamplerName);

	for(std::size_t i = 0; i < viewport::MAX; ++i)
	{
		glSamplerParameteri(SamplerName[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glSamplerParameteri(SamplerName[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glm::vec4 BorderColor(0.0f, 0.5f, 1.0f, 1.0f);
		glSamplerParameterfv(SamplerName[i], GL_TEXTURE_BORDER_COLOR, &BorderColor[0]);
	}

	glSamplerParameteri(SamplerName[viewport::V00], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(SamplerName[viewport::V10], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
	glSamplerParameteri(SamplerName[viewport::V11], GL_TEXTURE_WRAP_S, GL_REPEAT);
	glSamplerParameteri(SamplerName[viewport::V01], GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);

	glSamplerParameteri(SamplerName[viewport::V00], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glSamplerParameteri(SamplerName[viewport::V10], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
	glSamplerParameteri(SamplerName[viewport::V11], GL_TEXTURE_WRAP_T, GL_REPEAT);
	glSamplerParameteri(SamplerName[viewport::V01], GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);

	return glf::checkError("initSampler");
}
Beispiel #13
0
	//Apply sampler state settings
	void sampler_state::apply(rsx::fragment_texture& tex)
	{
		const f32 border_color = (f32)tex.border_color() / 255;
		const f32 border_color_array[] = { border_color, border_color, border_color, border_color };

		glSamplerParameteri(samplerHandle, GL_TEXTURE_WRAP_S, wrap_mode(tex.wrap_s()));
		glSamplerParameteri(samplerHandle, GL_TEXTURE_WRAP_T, wrap_mode(tex.wrap_t()));
		glSamplerParameteri(samplerHandle, GL_TEXTURE_WRAP_R, wrap_mode(tex.wrap_r()));
		glSamplerParameterfv(samplerHandle, GL_TEXTURE_BORDER_COLOR, border_color_array);

		if (tex.get_exact_mipmap_count() <= 1)
		{
			GLint min_filter = tex_min_filter(tex.min_filter());

			if (min_filter != GL_LINEAR && min_filter != GL_NEAREST)
			{
				switch (min_filter)
				{
				case GL_NEAREST_MIPMAP_NEAREST:
				case GL_NEAREST_MIPMAP_LINEAR:
					min_filter = GL_NEAREST; break;
				case GL_LINEAR_MIPMAP_NEAREST:
				case GL_LINEAR_MIPMAP_LINEAR:
					min_filter = GL_LINEAR; break;
				default:
					LOG_ERROR(RSX, "No mipmap fallback defined for rsx_min_filter = 0x%X", (u32)tex.min_filter());
					min_filter = GL_NEAREST;
				}
			}

			glSamplerParameteri(samplerHandle, GL_TEXTURE_MIN_FILTER, min_filter);
			glSamplerParameterf(samplerHandle,  GL_TEXTURE_LOD_BIAS, 0.f);
			glSamplerParameterf(samplerHandle,  GL_TEXTURE_MIN_LOD, -1000.f);
			glSamplerParameterf(samplerHandle,  GL_TEXTURE_MAX_LOD, 1000.f);
		}
		else
		{
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MIN_FILTER, tex_min_filter(tex.min_filter()));
			glSamplerParameterf(samplerHandle,  GL_TEXTURE_LOD_BIAS, tex.bias());
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MIN_LOD, (tex.min_lod() >> 8));
			glSamplerParameteri(samplerHandle,  GL_TEXTURE_MAX_LOD, (tex.max_lod() >> 8));
		}

		glSamplerParameteri(samplerHandle,  GL_TEXTURE_MAG_FILTER, tex_mag_filter(tex.mag_filter()));
		glSamplerParameterf(samplerHandle,  GL_TEXTURE_MAX_ANISOTROPY_EXT, ::gl::max_aniso(tex.max_aniso()));

		const u32 texture_format = tex.format() & ~(CELL_GCM_TEXTURE_UN | CELL_GCM_TEXTURE_LN);
		if (texture_format == CELL_GCM_TEXTURE_DEPTH16 || texture_format == CELL_GCM_TEXTURE_DEPTH24_D8)
		{
			//NOTE: The stored texture function is reversed wrt the textureProj compare function
			GLenum compare_mode = (GLenum)tex.zfunc() | GL_NEVER;

			switch (compare_mode)
			{
			case GL_GREATER: compare_mode = GL_LESS; break;
			case GL_GEQUAL: compare_mode = GL_LEQUAL; break;
			case GL_LESS: compare_mode = GL_GREATER; break;
			case GL_LEQUAL: compare_mode = GL_GEQUAL; break;
			}

			glSamplerParameteri(samplerHandle, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
			glSamplerParameteri(samplerHandle, GL_TEXTURE_COMPARE_FUNC, compare_mode);
		}
		else
			glSamplerParameteri(samplerHandle, GL_TEXTURE_COMPARE_MODE, GL_NONE);
	}
Beispiel #14
0
bool OGL_Sampler::Create(const SamplerDesc &desc)
{
  this->desc = desc;
  glGenSamplers(1, &samplerName); 

  switch(desc.filter)
  {
  case MIN_MAG_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_POINT_MAG_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_LINEAR_MAG_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_MAG_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_MAG_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_MAG_POINT_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_POINT_MAG_LINEAR_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_POINT_MAG_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_LINEAR_MAG_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_LINEAR_MAG_POINT_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_MAG_LINEAR_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case MIN_MAG_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER ,GL_LINEAR_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case ANISOTROPIC_FILTER:
    glSamplerParameterf(samplerName, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)desc.maxAnisotropy);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    break;

  case COMP_MIN_MAG_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_POINT_MAG_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_LINEAR_MAG_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_MAG_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_MAG_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_MAG_POINT_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_POINT_MAG_LINEAR_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_POINT_MAG_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_LINEAR_MAG_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_LINEAR_MAG_POINT_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_MAG_LINEAR_MIP_POINT_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_MIN_MAG_MIP_LINEAR_FILTER:
    glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;

  case COMP_ANISOTROPIC_FILTER:
    glSamplerParameterf(samplerName, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)desc.maxAnisotropy);
    glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    break;
  }
  glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_S, desc.adressU);
  glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_T, desc.adressV);
  glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_R, desc.adressW);
  glSamplerParameterfv(samplerName, GL_TEXTURE_BORDER_COLOR, desc.borderColor);
  glSamplerParameterf(samplerName, GL_TEXTURE_MIN_LOD, desc.minLOD);
  glSamplerParameterf(samplerName, GL_TEXTURE_MAX_LOD, desc.maxLOD);
  glSamplerParameterf(samplerName, GL_TEXTURE_LOD_BIAS, desc.lodBias);
  glSamplerParameteri(samplerName, GL_TEXTURE_COMPARE_FUNC, desc.compareFunc);
 
  return true;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL33_nglSamplerParameterfv(JNIEnv *__env, jclass clazz, jint sampler, jint pname, jlong paramsAddress, jlong __functionAddress) {
	const GLfloat *params = (const GLfloat *)(intptr_t)paramsAddress;
	glSamplerParameterfvPROC glSamplerParameterfv = (glSamplerParameterfvPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glSamplerParameterfv(sampler, pname, params);
}
Beispiel #16
0
void GLWrapper::SamplerParameterfv(GLuint samplerHandle, GLenum pname, const GLfloat * params)
{
	GLLOG(glSamplerParameterfv(samplerHandle, pname, params));ERROR_CHECK;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBSamplerObjects_nglSamplerParameterfv__IIJ(JNIEnv *__env, jclass clazz, jint sampler, jint pname, jlong paramsAddress) {
    glSamplerParameterfvPROC glSamplerParameterfv = (glSamplerParameterfvPROC)tlsGetFunction(675);
    intptr_t params = (intptr_t)paramsAddress;
    UNUSED_PARAM(clazz)
    glSamplerParameterfv(sampler, pname, params);
}
Beispiel #18
0
	//void OGL4Sampler::SetMipLodBias(int bias)
	//{
	//	assert(0);
	//	//glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_MODE, bias);
	//}
	void OGL4Sampler::SetBorderColor(const math::Color4& clr)
	{
		glSamplerParameterfv(m_sampler, GL_TEXTURE_BORDER_COLOR, clr.v);
	}
Beispiel #19
0
 void setBorderColor(float r=0,float g=0,float b=0,float a=0) {
     const float v__[] {r,g,b,a};
     glSamplerParameterfv(sampler_, GL_TEXTURE_BORDER_COLOR,v__);
 }
Beispiel #20
0
HdSimpleTextureResource::HdSimpleTextureResource(
    GlfTextureHandleRefPtr const &textureHandle, bool isPtex, 
        HdWrap wrapS, HdWrap wrapT, 
        HdMinFilter minFilter, HdMagFilter magFilter)
            : _textureHandle(textureHandle)
            , _texture(textureHandle->GetTexture())
            , _borderColor(0.0,0.0,0.0,0.0)
            , _maxAnisotropy(16.0)
            , _sampler(0)
            , _isPtex(isPtex)
{
    if (!glGenSamplers) { // GL initialization guard for headless unit test
        return;
    }

    // When we are not using Ptex we will use samplers,
    // that includes both, bindless textures and no-bindless textures
    if (!_isPtex) {
        // It is possible the texture provides wrap modes itself, in that
        // case we will use the wrap modes provided by the texture
        GLenum fwrapS = HdConversions::GetWrap(wrapS);
        GLenum fwrapT = HdConversions::GetWrap(wrapT);
        VtDictionary txInfo = _texture->GetTextureInfo();
        if (VtDictionaryIsHolding<GLuint>(txInfo, "wrapModeS")) {
            fwrapS = VtDictionaryGet<GLuint>(txInfo, "wrapModeS");
        }
        if (VtDictionaryIsHolding<GLuint>(txInfo, "wrapModeT")) {
            fwrapT = VtDictionaryGet<GLuint>(txInfo, "wrapModeT");
        }

        GLenum fminFilter = HdConversions::GetMinFilter(minFilter);
        GLenum fmagFilter = HdConversions::GetMagFilter(magFilter);
        if (!_texture->IsMinFilterSupported(fminFilter)) {
            fminFilter = GL_NEAREST;
        }
        if (!_texture->IsMagFilterSupported(fmagFilter)) {
            fmagFilter = GL_NEAREST;
        }

        glGenSamplers(1, &_sampler);
        glSamplerParameteri(_sampler, GL_TEXTURE_WRAP_S, fwrapS);
        glSamplerParameteri(_sampler, GL_TEXTURE_WRAP_T, fwrapT);
        glSamplerParameteri(_sampler, GL_TEXTURE_MIN_FILTER, fminFilter);
        glSamplerParameteri(_sampler, GL_TEXTURE_MAG_FILTER, fmagFilter);
        glSamplerParameterf(_sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, _maxAnisotropy);
        glSamplerParameterfv(_sampler, GL_TEXTURE_BORDER_COLOR, _borderColor.GetArray());
    }

    bool bindlessTexture = 
        HdRenderContextCaps::GetInstance().bindlessTextureEnabled;
    if (bindlessTexture) {
        size_t handle = GetTexelsTextureHandle();
        if (handle) {
            if (!glIsTextureHandleResidentNV(handle)) {
                glMakeTextureHandleResidentNV(handle);
            }
        }

        if (_isPtex) {
            handle = GetLayoutTextureHandle();
            if (handle) {
                if (!glIsTextureHandleResidentNV(handle)) {
                    glMakeTextureHandleResidentNV(handle);
                }
            }
        }
    }
}
//-----------------------------------------------------------------------------
CPUTResult CPUTRenderStateBlockOGL::LoadRenderStateBlock(const cString &fileName)
{
    // TODO: If already loaded, then Release() all the old members

    // use the fileName for now, maybe we'll add names later?
    mMaterialName = fileName;

    // Open/parse the file
    CPUTConfigFile file;
    CPUTResult result = file.LoadFile(fileName);
    ASSERT( !FAILED(result), _L("Failed loading file: '") + fileName + _L("'.") );

    // Note: We ignore "not found error" results for ReadProperties() calls.
    // These blocks are optional.
//    for( UINT ii=0; ii<8; ii++ )
//    {
//        char pBlockName[64];
//#ifndef CPUT_OS_WINDOWS
//        sprintf( pBlockName, _L("RenderTargetBlendStateOGL_%d"), ii+1 );
//#else
//        sprintf( pBlockName, ("RenderTargetBlendStateOGL_%d"), ii+1 );
//#endif
//    }

//#ifndef CPUT_OS_WINDOWS
//    ReadProperties( file, "DepthStencilStateOGL", pDepthStencilDescMap, &mStateDesc.DepthStencilDesc);
//    ReadProperties( file, "RasterizerStateOGL",   pRasterizerDescMap,   &mStateDesc.RasterizerDesc);
//    ReadProperties( file, "RenderTargetBlendStateOGL",   pRenderTargetBlendDescMap,   &mStateDesc.RenderTargetBlendDesc);
//#else
    ReadProperties( file, _L("DepthStencilStateOGL"), pDepthStencilDescMap, &mStateDesc.DepthStencilDesc);
    ReadProperties( file, _L("RasterizerStateOGL"),   pRasterizerDescMap,   &mStateDesc.RasterizerDesc);
    ReadProperties( file, _L("RenderTargetBlendStateOGL"),   pRenderTargetBlendDescMap,   &mStateDesc.RenderTargetBlendDesc);
//#endif

    //
    // For each sampler we read, need to create an OGL sampler object
    //
#ifndef CPUT_FOR_OGLES2
    GL_CHECK(ES3_COMPAT(glGenSamplers(1, &mStateDesc.DefaultSamplerID)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_MIN_FILTER,   mStateDesc.DefaultSamplerDesc.MinFilter)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_MAG_FILTER,   mStateDesc.DefaultSamplerDesc.MagFilter)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_WRAP_S,       mStateDesc.DefaultSamplerDesc.AddressU)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_WRAP_T,       mStateDesc.DefaultSamplerDesc.AddressV)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_WRAP_R,       mStateDesc.DefaultSamplerDesc.AddressW)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_COMPARE_MODE, mStateDesc.DefaultSamplerDesc.ComparisonMode)));
    GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.DefaultSamplerID, GL_TEXTURE_COMPARE_FUNC, mStateDesc.DefaultSamplerDesc.ComparisonFunc)));
    GL_CHECK(ES3_COMPAT(glSamplerParameterf( mStateDesc.DefaultSamplerID, GL_TEXTURE_MIN_LOD,      mStateDesc.DefaultSamplerDesc.MinLOD)));
    GL_CHECK(ES3_COMPAT(glSamplerParameterf( mStateDesc.DefaultSamplerID, GL_TEXTURE_MAX_LOD,      mStateDesc.DefaultSamplerDesc.MaxLOD)));
#ifndef CPUT_FOR_OGLES
    GL_CHECK(glSamplerParameterf( mStateDesc.DefaultSamplerID, GL_TEXTURE_LOD_BIAS,     mStateDesc.DefaultSamplerDesc.MipLODBias));
    GL_CHECK(glSamplerParameterfv(mStateDesc.DefaultSamplerID, GL_TEXTURE_BORDER_COLOR, mStateDesc.DefaultSamplerDesc.BorderColor));
#endif
#else
#warning "Need to do something with samplers here"
#endif
        
    mNumSamplers = 0;
    for( UINT ii=0; ii<NUM_SAMPLERS_PER_RENDERSTATE; ii++ )
    {
        // TODO: Use sampler names from .fx file.  Already did this for texture names.
        // The challenge is that the renderstate file is independent from the material (and the shaders).
        // Another feature is that the artists don't name the samplers (in the CPUTSL source).  Though, arbitrary .fx files can.
        // TODO: Add sampler-state properties to CPUTSL source (e.g., filter modes).  Then, have ShaderGenerator output a .rs file.
        char pBlockName[64];
#ifndef CPUT_OS_WINDOWS
        sprintf( pBlockName, _L("SamplerOGL_%d"), ii+1 );
        CPUTResult result = ReadProperties( file, cString(pBlockName), pSamplerDescMap, &mStateDesc.SamplerDesc[ii] );
#else
        sprintf( pBlockName, ("SamplerOGL_%d"), ii+1 );
        CPUTResult result = ReadProperties( file, cString(s2ws(pBlockName)), pSamplerDescMap, &mStateDesc.SamplerDesc[ii] );
#endif

        if( CPUT_SUCCESS != result )
        {
            break; // Reached last sampler spec
        }

#ifndef CPUT_FOR_OGLES2
        //
        // For each sampler we read, need to create an OGL sampler object
        //
        GL_CHECK(ES3_COMPAT(glGenSamplers(1, &mStateDesc.SamplerIDs[ii])));
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_MIN_FILTER,   mStateDesc.SamplerDesc[ii].MinFilter)));
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_MAG_FILTER,   mStateDesc.SamplerDesc[ii].MagFilter)));
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_WRAP_S,       mStateDesc.SamplerDesc[ii].AddressU)));
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_WRAP_T,       mStateDesc.SamplerDesc[ii].AddressV)));
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_WRAP_R,       mStateDesc.SamplerDesc[ii].AddressW)));
#ifndef CPUT_FOR_OGLES
        GL_CHECK(glSamplerParameterf( mStateDesc.SamplerIDs[ii], GL_TEXTURE_LOD_BIAS,     mStateDesc.SamplerDesc[ii].MipLODBias));
        GL_CHECK(glSamplerParameterfv(mStateDesc.SamplerIDs[ii], GL_TEXTURE_BORDER_COLOR, mStateDesc.SamplerDesc[ii].BorderColor));
#endif
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_COMPARE_MODE, mStateDesc.SamplerDesc[ii].ComparisonMode)));
        GL_CHECK(ES3_COMPAT(glSamplerParameteri( mStateDesc.SamplerIDs[ii], GL_TEXTURE_COMPARE_FUNC, mStateDesc.SamplerDesc[ii].ComparisonFunc)));
        GL_CHECK(ES3_COMPAT(glSamplerParameterf( mStateDesc.SamplerIDs[ii], GL_TEXTURE_MIN_LOD,      mStateDesc.SamplerDesc[ii].MinLOD)));
        GL_CHECK(ES3_COMPAT(glSamplerParameterf( mStateDesc.SamplerIDs[ii], GL_TEXTURE_MAX_LOD,      mStateDesc.SamplerDesc[ii].MaxLOD)));
#else
#warning "Need to do something with samplers here"
#endif

        ++mNumSamplers;
    }
 //   CreateNativeResources();

    return CPUT_SUCCESS;
} // CPUTRenderStateBlockOGL::LoadRenderStateBlock()
Beispiel #22
0
void
Sampler::setParameter(int aParameter, const glm::fvec4 &aParameterValues)
{
	GL_CHECKED_CALL(glSamplerParameterfv(value, aParameter, glm::value_ptr(aParameterValues)));
}
Beispiel #23
0
 void parameter(GLenum pname, GLfloat* param)
 {
   glSamplerParameterfv(m_sampler, pname, param);
 }