Ok whatever, here we go.
Variant 1.
Two sampler Objects.
Output as expected: http://prntscr.com/5zjdkf
Both textures has internal nearest filtering.
Sampler 1 (plane down) overrides, and change, filtering with linear filter.
Sampler 2 (plane up) overrides, but don’t change, filtering with nearest filtering.
So texture down is linear filtered, texture up nearest.
Pretty well.
namespace Betrayal
{
class BugPage : Page
{
private Frame camera = new Frame(FrameType.Camera);
private Frame plane1Frame = new Frame(FrameType.Model);
private Frame plane2Frame = new Frame(FrameType.Model);
private Shader_Tex shaderTex;
private TextureHandler textureHandler = new TextureHandler();
private GeoObject plane1;
private GeoObject plane2;
private int tex1, tex2;
private int sampler1, sampler2;
public BugPage(PageConstructorArgs cargs)
: base(cargs)
{ }
public override void Init()
{
shaderTex = new Shader_Tex(store.ShaderDir);
plane1 = new Plane(15, 15, 100);
plane1.Construct();
plane2 = new Plane(15, 15, 100);
plane2.Construct();
camera.Move(0, 0, 3);
plane1Frame.Move(0, -2, 0);
plane2Frame.Move(0, 2, 0);
//loading the same file twice just to be sure ...
tex1 = textureHandler.LoadTexture(Path.Combine(store.TexDir, "schach.jpg"), TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Repeat);
tex2 = textureHandler.LoadTexture(Path.Combine(store.TexDir, "schach.jpg"), TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Repeat);
}
public override void InitGL()
{
sampler1 = GL.GenSampler();
GL.SamplerParameter(sampler1, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.SamplerParameter(sampler1, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
sampler2 = GL.GenSampler();
GL.SamplerParameter(sampler2, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.SamplerParameter(sampler2, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
GL.Enable(EnableCap.DepthTest);
}
public override void Render()
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, state.Width / (float)state.Height, 0.01f, 1000.0f);
Matrix4 view = camera.GetMatrix();
GL.ActiveTexture(TextureUnit.Texture1);
GL.BindTexture(TextureTarget.Texture2D, tex1);
GL.BindSampler(1, sampler1);
GL.ActiveTexture(TextureUnit.Texture2);
GL.BindTexture(TextureTarget.Texture2D, tex2);
GL.BindSampler(2, sampler2);
shaderTex.UseProgram();
Matrix4 modelPlane1 = plane1Frame.GetMatrix();
MatrixPack mpPlane1 = new MatrixPack(modelPlane1, view, projection);
shaderTex.SetUniforms(mpPlane1.ModelViewProj, TextureUnit.Texture1);
plane1.Draw();
Matrix4 modelPlane2 = plane2Frame.GetMatrix();
MatrixPack mpPlane2 = new MatrixPack(modelPlane2, view, projection);
shaderTex.SetUniforms(mpPlane2.ModelViewProj, TextureUnit.Texture2);
plane2.Draw();
}
}
}
Variant 2.
One sampler Object.
Output weird: http://prntscr.com/5zje3g
Both textures has still internal nearest filtering.
Only one sampler is active now (for plane down).
Expected result:
Plane down is linear filtered due to sampler.
Plane up is nearest filtered due to texture internal parameters.
But as you see, both are linear filtered.
namespace Betrayal
{
class BugPage : Page
{
private Frame camera = new Frame(FrameType.Camera);
private Frame plane1Frame = new Frame(FrameType.Model);
private Frame plane2Frame = new Frame(FrameType.Model);
private Shader_Tex shaderTex;
private TextureHandler textureHandler = new TextureHandler();
private GeoObject plane1;
private GeoObject plane2;
private int tex1, tex2;
private int sampler1;//, sampler2;
public BugPage(PageConstructorArgs cargs)
: base(cargs)
{ }
public override void Init()
{
shaderTex = new Shader_Tex(store.ShaderDir);
plane1 = new Plane(15, 15, 100);
plane1.Construct();
plane2 = new Plane(15, 15, 100);
plane2.Construct();
camera.Move(0, 0, 3);
plane1Frame.Move(0, -2, 0);
plane2Frame.Move(0, 2, 0);
tex1 = textureHandler.LoadTexture(Path.Combine(store.TexDir, "schach.jpg"), TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Repeat);
tex2 = textureHandler.LoadTexture(Path.Combine(store.TexDir, "schach.jpg"), TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Repeat);
}
public override void InitGL()
{
sampler1 = GL.GenSampler();
GL.SamplerParameter(sampler1, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.SamplerParameter(sampler1, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
//sampler2 = GL.GenSampler();
//GL.SamplerParameter(sampler2, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
//GL.SamplerParameter(sampler2, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
GL.Enable(EnableCap.DepthTest);
}
public override void Render()
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, state.Width / (float)state.Height, 0.01f, 1000.0f);
Matrix4 view = camera.GetMatrix();
GL.ActiveTexture(TextureUnit.Texture1);
GL.BindTexture(TextureTarget.Texture2D, tex1);
GL.BindSampler(1, sampler1);
GL.ActiveTexture(TextureUnit.Texture2);
GL.BindTexture(TextureTarget.Texture2D, tex2);
// GL.BindSampler(2, sampler2);
shaderTex.UseProgram();
Matrix4 modelPlane1 = plane1Frame.GetMatrix();
MatrixPack mpPlane1 = new MatrixPack(modelPlane1, view, projection);
shaderTex.SetUniforms(mpPlane1.ModelViewProj, TextureUnit.Texture1);
plane1.Draw();
Matrix4 modelPlane2 = plane2Frame.GetMatrix();
MatrixPack mpPlane2 = new MatrixPack(modelPlane2, view, projection);
shaderTex.SetUniforms(mpPlane2.ModelViewProj, TextureUnit.Texture2);
plane2.Draw();
}
}
}