public RenderTarget(IGL owner, IntPtr handle, Texture2d tex) { Owner = owner; Id = handle; Texture2d = tex; tex.IsUpsideDown = true; }
public RenderTarget(IGL owner, object opaque, Texture2d tex) { Owner = owner; Opaque = opaque; Texture2d = tex; tex.IsUpsideDown = true; }
public void Set(Texture2d tex) { IntPtr handle; if (tex == null) handle = Owner.Owner.GetEmptyHandle(); else handle = tex.Id; Owner.Owner.SetPipelineUniformSampler(this, handle); }
public unsafe void Run(Texture2d tex, Size InputSize, Size OutputSize, bool flip) { flip = false; //test //ack! make sure to set the pipeline before setting uniforms Bind(); Pipeline["IN.video_size"].Set(new Vector2(InputSize.Width, InputSize.Height)); Pipeline["IN.texture_size"].Set(new Vector2(tex.Width, tex.Height)); Pipeline["IN.output_size"].Set(new Vector2(OutputSize.Width, OutputSize.Height)); Pipeline["IN.frame_count"].Set(1); //todo Pipeline["IN.frame_direction"].Set(1); //todo var Projection = Owner.CreateGuiProjectionMatrix(OutputSize); var Modelview = Owner.CreateGuiViewMatrix(OutputSize); var mat = Modelview * Projection; mat.Transpose(); Pipeline["modelViewProj"].Set(mat, true); Owner.SetTextureWrapMode(tex, true); sampler0.Set(tex); Owner.SetViewport(OutputSize); int w = OutputSize.Width; int h = OutputSize.Height; float v0,v1; if (flip) { v0 = 1; v1 = 0; } else { v0 = 0; v1 = 1; } float* pData = stackalloc float[10*4]; int i=0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 1; //topleft vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 0; pData[i++] = v0; pData[i++] = w; pData[i++] = 0; pData[i++] = 0; pData[i++] = 1; //topright vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 1; pData[i++] = v0; pData[i++] = 0; pData[i++] = h; pData[i++] = 0; pData[i++] = 1; //bottomleft vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 0; pData[i++] = v1; pData[i++] = w; pData[i++] = h; pData[i++] = 0; pData[i++] = 1; //bottomright vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 1; pData[i++] = v1; Owner.SetBlendState(Owner.BlendNoneCopy); Owner.BindArrayData(pData); Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); }
unsafe void PrepDrawSubrectInternal(Texture2d tex) { if (sTexture != tex) { sTexture = tex; CurrPipeline["uSampler0"].Set(tex); if (sTexture == null) { CurrPipeline["uSamplerEnable"].Set(false); } else { CurrPipeline["uSamplerEnable"].Set(true); } } if (_Projection.IsDirty) { CurrPipeline["um44Projection"].Set(ref _Projection.Top, false); _Projection.IsDirty = false; } if (_Modelview.IsDirty) { CurrPipeline["um44Modelview"].Set(ref _Modelview.Top, false); _Modelview.IsDirty = false; } }
public void Set(Texture2d tex) { if (Owner == null) return; //uniform was optimized out Owner.Owner.SetPipelineUniformSampler(this, tex); }
public void Draw(Texture2d tex) { DrawInternal(tex, 0, 0, tex.Width, tex.Height); }
public void Draw(Texture2d art, float x, float y, float width, float height) { DrawInternal(art, x, y, width, height); }
public void SetTextureWrapMode(Texture2d tex, bool clamp) { if (CurrentBoundTexture == null) throw new InvalidOperationException(); }
public void TexParameter2d(Texture2d tex, TextureParameterName pname, int param) { BindTexture2d(tex); GL.TexParameter(TextureTarget.Texture2D, (global::OpenTK.Graphics.OpenGL.TextureParameterName)pname, param); }
public unsafe RenderTarget CreateRenderTarget(int w, int h) { TextureWrapper tw = new TextureWrapper(); tw.SDBitmap = new Bitmap(w,h, sdi.PixelFormat.Format32bppArgb); IntPtr texid = GenTexture(); ResourceIDs.Lookup[texid.ToInt32()] = tw; var tex = new Texture2d(this, texid, null, w, h); var rt = new RenderTarget(this, ResourceIDs.Alloc(ResourceIdManager.EResourceType.RenderTarget), tex); int id = rt.Id.ToInt32(); RenderTargetWrapper rtw = new RenderTargetWrapper(this); rtw.Target = rt; ResourceIDs.Lookup[id] = rtw; return rt; }
public unsafe void Run(Texture2d tex, Size InputSize, Size OutputSize, bool flip) { flip = false; //test //ack! make sure to set the pipeline before setting uniforms Bind(); Pipeline["IN.video_size"].Set(new Vector2(InputSize.Width, InputSize.Height)); Pipeline["IN.texture_size"].Set(new Vector2(tex.Width, tex.Height)); Pipeline["IN.output_size"].Set(new Vector2(OutputSize.Width, OutputSize.Height)); Pipeline["IN.frame_count"].Set(1); //todo Pipeline["IN.frame_direction"].Set(1); //todo var Projection = Owner.CreateGuiProjectionMatrix(OutputSize); var Modelview = Owner.CreateGuiViewMatrix(OutputSize); var mat = Matrix4.Transpose(Modelview * Projection); Pipeline["modelViewProj"].Set(mat, true); Owner.SetTextureWrapMode(tex, true); sampler0.Set(tex); Owner.SetViewport(OutputSize); float time = DateTime.Now.Second + (float)DateTime.Now.Millisecond / 1000; Pipeline["Time"].Set(time); int w = OutputSize.Width; int h = OutputSize.Height; float v0, v1; if (flip) { v0 = 1; v1 = 0; } else { v0 = 0; v1 = 1; } float *pData = stackalloc float[10 * 4]; int i = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 1; //topleft vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 0; pData[i++] = v0; pData[i++] = w; pData[i++] = 0; pData[i++] = 0; pData[i++] = 1; //topright vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 1; pData[i++] = v0; pData[i++] = 0; pData[i++] = h; pData[i++] = 0; pData[i++] = 1; //bottomleft vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 0; pData[i++] = v1; pData[i++] = w; pData[i++] = h; pData[i++] = 0; pData[i++] = 1; //bottomright vert pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; pData[i++] = 0; //useless color pData[i++] = 1; pData[i++] = v1; Owner.SetBlendState(Owner.BlendNoneCopy); Owner.BindArrayData(new(pData)); Owner.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); }
public void BindTexture2d(Texture2d tex) { CurrentBoundTexture = tex; }
unsafe void DrawSubrectInternal(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1) { PrepDrawSubrectInternal(tex); EmitRectangleInternal(x, y, w, h, u0, v0, u1, v1); }
public void Draw(Texture2d tex, float x, float y) { DrawInternal(tex, x, y, tex.Width, tex.Height); }
private void BindTexture2d(Texture2d tex) { GL.BindTexture(TextureTarget.Texture2D, (int)tex.Opaque); }
public void LoadTextureData(Texture2d tex, BitmapBuffer bmp) { bmp.ToSysdrawingBitmap(BitmapForTexture(tex)); }
public RenderTarget CreateRenderTarget(int w, int h) { var d3dtex = new d3d9.Texture(dev, w, h, 1, d3d9.Usage.RenderTarget, d3d9.Format.A8R8G8B8, d3d9.Pool.Default); var tw = new TextureWrapper() { Texture = d3dtex }; var tex = new Texture2d(this, tw, w, h); RenderTarget rt = new RenderTarget(this, tw, tex); return rt; }
public void DrawSubrect(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1) { DrawSubrectInternal(tex, x, y, w, h, u0, v0, u1, v1); }
public sd.Bitmap BitmapForTexture(Texture2d tex) { return TextureWrapperForTexture(tex).SDBitmap; }
public void SetPipeline(Pipeline pipeline) { if (IsActive) throw new InvalidOperationException("Can't change pipeline while renderer is running!"); Flush(); CurrPipeline = pipeline; //clobber state cache sTexture = null; //save the modulate color? user beware, I guess, for now. }
public void FreeTexture(Texture2d tex) { ResourceIDs.Free(tex.Id); }
public void FreeTexture(Texture2d tex) { var tw = tex.Opaque as TextureWrapper; tw.Texture.Dispose(); }
public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex) { //todo return null; }
public void SetPipelineUniformSampler(PipelineUniform uniform, Texture2d tex) { if (uniform.Owner == null) return; //uniform was optimized out var tw = tex.Opaque as TextureWrapper; foreach (var ui in uniform.UniformInfos) { var uw = ui.Opaque as UniformWrapper; dev.SetTexture(uw.SamplerIndex, tw.Texture); dev.SetSamplerState(uw.SamplerIndex, SamplerState.AddressU, tw.WrapClamp); dev.SetSamplerState(uw.SamplerIndex, SamplerState.AddressV, tw.WrapClamp); dev.SetSamplerState(uw.SamplerIndex, SamplerState.MinFilter, tw.MinFilter); dev.SetSamplerState(uw.SamplerIndex, SamplerState.MagFilter, tw.MagFilter); } }
public TextureWrapper TextureWrapperForTexture(Texture2d tex) { return ResourceIDs.Lookup[tex.Id.ToInt32()] as TextureWrapper; }
public void SetTextureWrapMode(Texture2d tex, bool clamp) { var tw = tex.Opaque as TextureWrapper; tw.WrapClamp = clamp ? TextureAddress.Clamp : TextureAddress.Wrap; }
public void TexParameter2d(Texture2d tex, gl.TextureParameterName pname, int param) { var tw = tex.Opaque as TextureWrapper; if(pname == gl.TextureParameterName.TextureMinFilter) tw.MinFilter = (param == (int)gl.TextureMinFilter.Linear) ? TextureFilter.Linear : TextureFilter.Point; if (pname == gl.TextureParameterName.TextureMagFilter) tw.MagFilter = (param == (int)gl.TextureMagFilter.Linear) ? TextureFilter.Linear : TextureFilter.Point; }
public unsafe void LoadTextureData(Texture2d tex, BitmapBuffer bmp) { sdi.BitmapData bmp_data = bmp.LockBits(); var tw = tex.Opaque as TextureWrapper; var dr = tw.Texture.LockRectangle(0, LockFlags.None); //TODO - do we need to handle odd sizes, weird pitches here? if (bmp.Width * 4 != bmp_data.Stride) throw new InvalidOperationException(); dr.Data.WriteRange(bmp_data.Scan0, bmp.Width * bmp.Height * 4); dr.Data.Close(); tw.Texture.UnlockRectangle(0); bmp.UnlockBits(bmp_data); }
unsafe void DrawInternal(Texture2d tex, float x, float y, float w, float h) { Art art = new Art(null); art.Width = w; art.Height = h; art.u0 = art.v0 = 0; art.u1 = art.v1 = 1; art.BaseTexture = tex; DrawInternal(art, x, y, w, h, false, tex.IsUpsideDown); }
public Texture2d LoadTexture(BitmapBuffer bmp) { var tex = new d3d9.Texture(dev, bmp.Width, bmp.Height, 1, d3d9.Usage.None, d3d9.Format.A8R8G8B8, d3d9.Pool.Managed); var tw = new TextureWrapper() { Texture = tex }; var ret = new Texture2d(this, tw, bmp.Width, bmp.Height); LoadTextureData(ret, bmp); return ret; }
public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex) { //TODO - lazy create and cache resolving target in RT var target = new d3d9.Texture(dev, tex.IntWidth, tex.IntHeight, 1, d3d9.Usage.None, d3d9.Format.A8R8G8B8, d3d9.Pool.SystemMemory); var tw = tex.Opaque as TextureWrapper; dev.GetRenderTargetData(tw.Texture.GetSurfaceLevel(0), target.GetSurfaceLevel(0)); var dr = target.LockRectangle(0, LockFlags.ReadOnly); if (dr.Pitch != tex.IntWidth * 4) throw new InvalidOperationException(); int[] pixels = new int[tex.IntWidth * tex.IntHeight]; dr.Data.ReadRange(pixels, 0, tex.IntWidth * tex.IntHeight); var bb = new BitmapBuffer(tex.IntWidth, tex.IntHeight, pixels); target.UnlockRectangle(0); target.Dispose(); //buffer churn warning return bb; }
public void SetTexture(Texture2d tex) { Texture = tex; }
public void FreeTexture(Texture2d tex) { GL.DeleteTexture((int)tex.Opaque); }