1 module armos.graphics.sampler; 2 3 import derelict.opengl3.gl; 4 5 /++ 6 +/ 7 class Sampler { 8 public{ 9 /// 10 this(){ 11 glGenSamplers(1, cast(uint*)&_id); 12 //TODO 13 glSamplerParameteri (_id, GL_TEXTURE_WRAP_S, GL_REPEAT); 14 glSamplerParameteri (_id, GL_TEXTURE_WRAP_T, GL_REPEAT); 15 glSamplerParameteri (_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 16 glSamplerParameteri (_id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 17 18 _textureUnit = 0; 19 } 20 21 /// 22 ~this(){ 23 glDeleteSamplers(1, cast(uint*)&_id); 24 } 25 26 /// 27 void begin(){ 28 int savedID; 29 glGetIntegerv(GL_SAMPLER_BINDING ,&savedID); 30 _savedIDs ~= savedID; 31 glBindSampler(0, _id); 32 } 33 34 /// 35 int textureUnit()const{ 36 return _textureUnit; 37 } 38 39 /// 40 Sampler textureUnit(in int n){ 41 _textureUnit = n; 42 return this; 43 } 44 45 /// 46 void end(){ 47 import std.range; 48 glBindSampler(_textureUnit, _savedIDs[$-1]); 49 if (_savedIDs.length == 0) { 50 assert(_textureUnit, "stack is empty"); 51 }else{ 52 _savedIDs.popBack; 53 } 54 } 55 }//public 56 57 private{ 58 int _id; 59 int[] _savedIDs; 60 int _textureUnit; 61 }//private 62 }//class Sampler