public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable)
        {
            var c  = (VeldridRendererContext)context;
            var cl = c.CommandList;
            var gd = c.GraphicsDevice;
            var sc = c.SceneContext;

            ITextureManager textureManager = Resolve <ITextureManager>();
            var             window         = renderable as TileMapWindow;

            if (window == null)
            {
                return;
            }

            var tilemap = window.TileMap;

            cl.PushDebugGroup($"Tiles3D:{tilemap.Name}:{tilemap.RenderOrder}");
            TextureView floors = (TextureView)textureManager.GetTexture(tilemap.Floors);
            TextureView walls  = (TextureView)textureManager.GetTexture(tilemap.Walls);

            var miscUniformData = new MiscUniformData {
                TileSize = tilemap.TileSize, Unused1 = 0
            };

            cl.UpdateBuffer(_miscUniformBuffer, 0, miscUniformData);

            var resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(_layout,
                                                                                              _miscUniformBuffer,
                                                                                              gd.PointSampler,
                                                                                              _textureSampler,
                                                                                              floors,
                                                                                              walls));

            resourceSet.Name = $"RS_TileMap:{tilemap.Name}";
            _resourceSets.Add(resourceSet);

            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vb);
            cl.SetVertexBuffer(1, _instanceBuffers[window.InstanceBufferId]);
            cl.SetIndexBuffer(_ib, IndexFormat.UInt16);

            cl.DrawIndexed((uint)Indices.Length, (uint)window.Length, 0, 0, 0);
            cl.PopDebugGroup();
        }
Beispiel #2
0
        public GL46Texture(int width, int height, Filter filter, TextureAddressMode textureAddressMode, ref float[] pixelData)
        {
            _width  = width;
            _height = height;
            OpenTK.Graphics.OpenGL4.GL.CreateTextures(TextureTarget.Texture2D, 1, out _nativeTexture);
            OpenTK.Graphics.OpenGL4.GL.TextureStorage2D(_nativeTexture, 1, SizedInternalFormat.Rgba32f, width, height);

            OpenTK.Graphics.OpenGL4.GL.TextureParameter(_nativeTexture, TextureParameterName.TextureMinFilter, (int)filter.MinFilterToOpenTK());
            OpenTK.Graphics.OpenGL4.GL.TextureParameter(_nativeTexture, TextureParameterName.TextureMagFilter, (int)filter.MagFilterToOpenTK());
            OpenTK.Graphics.OpenGL4.GL.TextureParameter(_nativeTexture, TextureParameterName.TextureWrapR, (int)textureAddressMode.ToOpenTK());
            OpenTK.Graphics.OpenGL4.GL.TextureParameter(_nativeTexture, TextureParameterName.TextureWrapS, (int)textureAddressMode.ToOpenTK());
            OpenTK.Graphics.OpenGL4.GL.TextureParameter(_nativeTexture, TextureParameterName.TextureWrapT, (int)textureAddressMode.ToOpenTK());

            OpenTK.Graphics.OpenGL4.GL.TextureSubImage2D(_nativeTexture, 0, 0, 0, width, height, PixelFormat.Rgba, PixelType.Float, pixelData);

            View = new GL46TextureView(this);
        }
Beispiel #3
0
        public void ChangeSource(Guid source, SharpMedia.Math.Vector2i?newSize)
        {
            lock (syncRoot)
            {
                AssertNotDisposed();
                if (newSize.HasValue)
                {
                    size = newSize.Value;
                    AdjustSize();
                }

                renderData.Dispose();

                renderDataId = source;
                renderData   = (manager.Device.GetShared(source) as TypelessTexture2D).CreateTexture();
            }
        }
Beispiel #4
0
        public TextRenderer(GraphicsDevice gd)
        {
            _gd = gd;
            uint width  = 250;
            uint height = 100;

            _texture = gd.ResourceFactory.CreateTexture(
                TextureDescription.Texture2D(width, height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));
            TextureView = gd.ResourceFactory.CreateTextureView(_texture);

            FontCollection fc     = new FontCollection();
            FontFamily     family = fc.Install(Path.Combine(AppContext.BaseDirectory, "Assets", "Fonts", "Sunflower-Medium.ttf"));

            _font = family.CreateFont(28);

            _image = new Image <Rgba32>(250, 100);
        }
Beispiel #5
0
 public void DisposeTextures()
 {
     for (int i = 0; i < textures.Count; i++)
     {
         Texture     texture   = textures[i];
         TextureView view      = textureViews[i];
         TextureView imguiView = imguiTextureViews[i];
         view.Dispose();
         imguiView.Dispose();
         texture.Dispose();
     }
     textures.Clear();
     textureViews.Clear();
     imguiTextureViews.Clear();
     imguiTextures.Clear();
     forceRecreate = true;
 }
Beispiel #6
0
        private void StartCapture(int width, int height)
        {
            if (capturing)
            {
                return;
            }

            capturing = true;
            TextureView previewView = FindViewById <TextureView>(Resource.Id.CameraPreviewView);
            int         status      = CameraHelper.StartCapture(previewView.SurfaceTexture, new Size(width, height));

            if (status != 0)
            {
                Toast.MakeText(ApplicationContext, $"Error {status} while trying to start capture.", ToastLength.Long).Show();
                capturing = false;
            }
        }
Beispiel #7
0
        /// <summary>
        ///     Gets or creates a handle for a texture to be drawn with ImGui.
        ///     Pass the returned handle to Image() or ImageButton().
        /// </summary>
        public IntPtr GetOrCreateImGuiBinding(ResourceFactory factory, TextureView textureView)
        {
            if (_setsByView.TryGetValue(textureView, out var rsi))
            {
                return(rsi.ImGuiBinding);
            }

            var resourceSet = factory.CreateResourceSet(new ResourceSetDescription(_textureLayout, textureView));

            rsi = new ResourceSetInfo(GetNextImGuiBindingId(), resourceSet);

            _setsByView.Add(textureView, rsi);
            _viewsById.Add(rsi.ImGuiBinding, rsi);
            _ownedResources.Add(resourceSet);

            return(rsi.ImGuiBinding);
        }
Beispiel #8
0
        /// <summary>
        /// Gets or creates a handle for a texture to be drawn with ImGui.
        /// Pass the returned handle to Image() or ImageButton().
        /// </summary>
        public IntPtr GetOrCreateImGuiBinding(ResourceFactory factory, TextureView textureView)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            if (!setsByView.TryGetValue(textureView, out ResourceSetInfo rsi))
            {
                ResourceSet resourceSet = factory.CreateResourceSet(new ResourceSetDescription(textureLayout, textureView));
                rsi = new ResourceSetInfo(GetNextImGuiBindingID(), resourceSet);

                setsByView.Add(textureView, rsi);
                viewsById.Add(rsi.ImGuiBinding, rsi);
                ownedResources.Add(resourceSet);
            }

            return(rsi.ImGuiBinding);
        }
Beispiel #9
0
        public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable)
        {
            var c  = (VeldridRendererContext)context;
            var cl = c.CommandList;
            var sc = c.SceneContext;

            ITextureManager      textureManager = Resolve <ITextureManager>();
            IDeviceObjectManager dom            = Resolve <IDeviceObjectManager>();
            var config = Resolve <CoreConfig>().Visual.Skybox;

            if (!(Resolve <ICamera>() is PerspectiveCamera camera))
            {
                return;
            }

            var skybox = (SkyboxRenderable)renderable;

            cl.PushDebugGroup(skybox.Name);

            var uniformInfo = new SkyboxUniformInfo
            {
                uYaw               = camera.Yaw,
                uPitch             = camera.Pitch,
                uVisibleProportion = config.VisibleProportion
            };

            cl.UpdateBuffer(_uniformBuffer, 0, uniformInfo);

            if (sc.PaletteView == null)
            {
                return;
            }

            TextureView textureView = (TextureView)textureManager?.GetTexture(skybox.Texture);
            var         resourceSet = dom.Get <ResourceSet>((skybox, textureView));

            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vertexBuffer);
            cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);

            cl.DrawIndexed((uint)Indices.Length, 1, 0, 0, 0);
            cl.PopDebugGroup();
        }
Beispiel #10
0
        public int GetOrAllocateTextureID(TextureView texture, int priorityClass = 0)
        {
            if (!new Rectangle2(new Vector2(), texture.Texture.Image.Size).Contains(texture.Area))
            {
                throw new ArgumentOutOfRangeException(nameof(texture.Area));
            }

            if (texture.Area.X0 < 0 || texture.Area.Y0 < 0 || texture.Area.X1 < 0 || texture.Area.Y1 < 0)
            {
                return(-1); // Negative texture coordinates found!
            }
            if (texture.Area.Width > _pageSize || texture.Area.Height > _pageSize)
            {
                return(-1); // Texture page too big!
            }
            // Deduplicate hashed textures
            {
                TextureHashed textureHashed = texture.Texture as TextureHashed;
                if (textureHashed != null)
                {
                    Texture existingTexture;
                    if (_hashedTextures.TryGetValue(textureHashed.Hash, out existingTexture))
                    {
                        texture.Texture = existingTexture;
                    }
                    else
                    {
                        _hashedTextures.Add(textureHashed.Hash, texture.Texture);
                    }
                }
            }

            // Check texture
            int textureID;

            if (_usedTexturesLookup.TryGetValue(texture, out textureID))
            {
                return(textureID);
            }

            textureID = _usedTextures.Count;
            _usedTextures.Add(texture);
            _usedTexturesLookup.Add(texture, textureID);
            return(textureID);
        }
Beispiel #11
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            Window.RequestFeature(WindowFeatures.NoTitle);

            SetContentView(sensorviz_xamarin.Resource.Layout.Main);

            //add camera texture view
            textureView = FindViewById <TextureView>(sensorviz_xamarin.Resource.Id.textureView1);
            textureView.SurfaceTextureListener = this;

            //add proximity layout
            LinearLayout lightLayout = FindViewById <LinearLayout>(sensorviz_xamarin.Resource.Id.light);

            light = new LightView(lightLayout);

            //add proximity layout
            LinearLayout proximityLayout = FindViewById <LinearLayout>(sensorviz_xamarin.Resource.Id.proximity);

            proximity = new ProximityView(proximityLayout);

            //add compass layout
            LinearLayout compassLayout = FindViewById <LinearLayout>(sensorviz_xamarin.Resource.Id.compass);

            compass = new CompassView(compassLayout);

            //add accelerometer layout
            LinearLayout accelerometerLayout = FindViewById <LinearLayout>(sensorviz_xamarin.Resource.Id.accelerometer);

            accelerometer = new AccelerometerView(accelerometerLayout);

            //get Sensor manager
            sensorService = (SensorManager)GetSystemService(Context.SensorService);

            proximitySensor = sensorService.GetDefaultSensor(SensorType.Proximity);
            lightSensor     = sensorService.GetDefaultSensor(SensorType.Light);         // Get a Light Sensor
            ori             = sensorService.GetDefaultSensor(SensorType.Orientation);   //Get orientation
            acc             = sensorService.GetDefaultSensor(SensorType.Accelerometer); //Get orientation

            // Register a listeners
            sensorService.RegisterListener(proximity, proximitySensor, Android.Hardware.SensorDelay.Normal);
            sensorService.RegisterListener(light, lightSensor, Android.Hardware.SensorDelay.Game);
            sensorService.RegisterListener(compass, ori, SensorDelay.Fastest);
            sensorService.RegisterListener(accelerometer, acc, SensorDelay.Fastest);
        }
Beispiel #12
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);


            cameraView     = FindViewById <TextureView>(Resource.Id.Texture_View);
            changeContrast = FindViewById <Button>(Resource.Id.changeContrast);
            changeZoom     = FindViewById <Button>(Resource.Id.changeZoom);
            handler        = new Handler();

            changeContrast.Click += ChangeContrast_Click;
            changeZoom.Click     += ChangeZoom_Click;

            aCamera = new ACamera(this, Android.Hardware.Camera2.LensFacing.Back, handler, cameraView);
        }
Beispiel #13
0
 public virtual void Setup()
 {
     Disposables     = new List <IDisposable>();
     GraphicsDevice  = GraphicsDevice.CreateVulkan(new GraphicsDeviceOptions(false));
     ResourceFactory = GraphicsDevice.ResourceFactory;
     _offscreenColor = ResourceFactory.CreateTexture(TextureDescription.Texture2D(
                                                         Width, Height, 1, 1,
                                                         PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled));
     _stagingTextrue = ResourceFactory.CreateTexture(TextureDescription.Texture2D(
                                                         Width, Height, 1, 1,
                                                         PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging));
     _offscreenDepth = ResourceFactory.CreateTexture(TextureDescription.Texture2D(
                                                         Width, Height, 1, 1, PixelFormat.R16_UNorm, TextureUsage.DepthStencil));
     Framebuffer =
         ResourceFactory.CreateFramebuffer(new FramebufferDescription(_offscreenDepth, _offscreenColor));
     _offscreenView = ResourceFactory.CreateTextureView(_offscreenColor);
     CommandList    = ResourceFactory.CreateCommandList();
 }
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        _textureView = (TextureView)FindViewById(Resource.Id.textureView);
        _textureView.SurfaceTextureListener = this;

        _surfaceView = (SurfaceView)FindViewById(Resource.Id.surfaceview);
        //set to top layer
        _surfaceView.SetZOrderOnTop(true);
        //set the background to transparent
        _surfaceView.Holder.SetFormat(Format.Transparent);
        holder              = _surfaceView.Holder;
        _surfaceView.Touch += _surfaceView_Touch;
    }
Beispiel #15
0
        void SetupUserInterface()
        {
            _activity = this.Context as Activity;
            if (_activity != null)
            {
                _activity.Window.DecorView.SystemUiVisibility = (StatusBarVisibility)WindowFlags;
                _activity.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
                _view = _activity.LayoutInflater.Inflate(Resource.Layout.GamestreamLayout, this, false);
            }

            _textureView = _view.FindViewById <TextureView>(Resource.Id.textureView);
            _textureView.SurfaceTextureListener = this;

            _recordButton = _view.FindViewById <global::Android.Widget.Button>(Resource.Id.recordButton);
            _exitButton   = _view.FindViewById <global::Android.Widget.Button>(Resource.Id.exitButton);

            HideButtons();
        }
Beispiel #16
0
        public void Initialize()
        {
            var device  = _renderer.Device;
            var factory = device.ResourceFactory;

            BufferDescription vbDescription = new BufferDescription(
                4 * VertexPositionTextureColor.SizeInBytes,
                BufferUsage.VertexBuffer);

            vertexBuffer = AddDisposable(factory.CreateBuffer(vbDescription));

            BufferDescription ibDescription = new BufferDescription(
                4 * sizeof(ushort),
                BufferUsage.IndexBuffer);

            indexBuffer = AddDisposable(factory.CreateBuffer(ibDescription));

            var topLeft     = new Vector2(0, 0);
            var topRight    = new Vector2(0 + Size.X, 0);
            var bottomLeft  = new Vector2(0, 0 + Size.Y);
            var bottomRight = new Vector2(0 + Size.X, 0 + Size.Y);

            VertexPositionTextureColor[] quadVertices =
            {
                new VertexPositionTextureColor(topLeft,     new Vector2(0f, 0f), RgbaFloat.White),
                new VertexPositionTextureColor(topRight,    new Vector2(1f, 0f), RgbaFloat.White),
                new VertexPositionTextureColor(bottomLeft,  new Vector2(0f, 1f), RgbaFloat.White),
                new VertexPositionTextureColor(bottomRight, new Vector2(1f, 1f), RgbaFloat.White)
            };
            ushort[] quadIndices = { 0, 1, 2, 3 };

            device.UpdateBuffer(vertexBuffer, 0, quadVertices);
            device.UpdateBuffer(indexBuffer, 0, quadIndices);

            textCache   = AddDisposable(new TextCache(device));
            Font        = SystemFonts.CreateFont(FontName, FontSize, FontStyle);
            texture     = AddDisposable(textCache.GetTextTexture(Content, Font, TextAlignment, Color, Size));
            textureView = AddDisposable(device.ResourceFactory.CreateTextureView(texture));

            textureSet = AddDisposable(device.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                                    _renderer.Shader.TextureLayout,
                                                                                    textureView,
                                                                                    device.Aniso4xSampler)));
        }
Beispiel #17
0
        public void UpdatePerFrameResources(IRendererContext context, IEnumerable <IRenderable> renderables, IList <IRenderable> results)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (renderables == null)
            {
                throw new ArgumentNullException(nameof(renderables));
            }
            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }
            var c  = (VeldridRendererContext)context;
            var gd = c.GraphicsDevice;

            if (!(renderables.FirstOrDefault() is SkyboxRenderable skybox))
            {
                return;
            }

            ITextureManager      textureManager = Resolve <ITextureManager>();
            IDeviceObjectManager objectManager  = Resolve <IDeviceObjectManager>();

            textureManager?.PrepareTexture(skybox.Texture, context);
            TextureView textureView = (TextureView)textureManager?.GetTexture(skybox.Texture);

            var resourceSet = objectManager.GetDeviceObject <ResourceSet>((skybox, textureView, null));

            if (resourceSet == null)
            {
                resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                       _resourceLayout,
                                                                       gd.PointSampler,
                                                                       textureView,
                                                                       _uniformBuffer));
                resourceSet.Name = $"RS_Sky:{skybox.Texture.Name}";
                PerfTracker.IncrementFrameCounter("Create ResourceSet");
                objectManager.SetDeviceObject((skybox, textureView, null), resourceSet);
            }

            results.Add(skybox);
        }
Beispiel #18
0
        public void Render(GraphicsDevice gd, CommandList cl, SceneContext sc, RenderPasses renderPass, IRenderable renderable)
        {
            ITextureManager textureManager = Resolve <ITextureManager>();
            // float depth = gd.IsDepthRangeZeroToOne ? 0 : 1;
            var sprite    = (MultiSprite)renderable;
            var shaderKey = new SpriteShaderKey(
                sprite.Key.Texture.ArrayLayers > 1,
                !sprite.Flags.HasFlag(SpriteFlags.NoDepthTest));

            //if (!shaderKey.UseArrayTexture)
            //    return;

            cl.PushDebugGroup($"Sprite:{sprite.Key.Texture.Name}:{sprite.Key.RenderOrder}");
            TextureView textureView = textureManager?.GetTexture(sprite.Key.Texture);

            if (sc.PaletteView == null)
            {
                return;
            }

            var resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                       _perSpriteResourceLayout,
                                                                       sc.ProjectionMatrixBuffer,
                                                                       sc.ModelViewMatrixBuffer,
                                                                       gd.PointSampler,
                                                                       textureView,
                                                                       sc.PaletteView
                                                                       ));

            resourceSet.Name = $"RS_Sprite:{sprite.Key.Texture.Name}";
            _resourceSets.Add(resourceSet);

            cl.SetPipeline(_pipelines[shaderKey]);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vertexBuffer);
            cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            cl.SetVertexBuffer(1, _instanceBuffers[sprite.BufferId]);

            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, depth, depth));
            cl.DrawIndexed((uint)Indices.Length, (uint)sprite.Instances.Length, 0, 0, 0);
            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, 0, 1));
            cl.PopDebugGroup();
        }
Beispiel #19
0
        public void Render(GraphicsDevice gd, CommandList cl, SceneContext sc, RenderPasses renderPass, IRenderable renderable)
        {
            ITextureManager textureManager = Resolve <ITextureManager>();
            var             window         = renderable as TileMapWindow;

            if (window == null)
            {
                return;
            }

            var tilemap = window.TileMap;

            cl.PushDebugGroup($"Tiles3D:{tilemap.Name}:{tilemap.RenderOrder}");
            TextureView floors = textureManager.GetTexture(tilemap.Floors);
            TextureView walls  = textureManager.GetTexture(tilemap.Walls);

            var miscUniformData = new MiscUniformData {
                Position = tilemap.Position, TileSize = tilemap.TileSize, Unused1 = 0, Unused2 = 0
            };

            cl.UpdateBuffer(_miscUniformBuffer, 0, miscUniformData);

            var resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(_layout,
                                                                                              sc.ProjectionMatrixBuffer,
                                                                                              sc.ModelViewMatrixBuffer,
                                                                                              _miscUniformBuffer,
                                                                                              gd.PointSampler,
                                                                                              sc.PaletteView,
                                                                                              _textureSampler,
                                                                                              floors,
                                                                                              walls));

            _resourceSets.Add(resourceSet);

            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vb);
            cl.SetVertexBuffer(1, _instanceBuffers[window.InstanceBufferId]);
            cl.SetIndexBuffer(_ib, IndexFormat.UInt16);

            cl.DrawIndexed((uint)Indices.Length, (uint)window.Length, 0, 0, 0);
            cl.PopDebugGroup();
        }
Beispiel #20
0
        public void SetTexture(TextureView texView)
        {
            if (texView == null)
            {
                _ExtTextureSet = null; return;
            }

            if (_OwnerTextureResourceSets.TryGetValue(texView, out var textureSet))
            {
                _ExtTextureSet = textureSet; return;
            }

            var rsetDesc = new ResourceSetDescription(_OwnedTextureLayout, texView);

            textureSet = _ExtDevice.ResourceFactory.CreateResourceSet(rsetDesc);
            _OwnerTextureResourceSets[texView] = textureSet;

            _ExtTextureSet = textureSet;
        }
Beispiel #21
0
        private void findView()
        {
            textureViewOne = (TextureView)FindViewById(Resource.Id.texture_view_one);
            textureViewOne.SetOpaque(false);
            textureView = (TextureView)FindViewById(Resource.Id.texture_view);
            textureView.SetOpaque(false);
            surface_one          = (SurfaceView)FindViewById(Resource.Id.surface_one);
            surface_two          = (SurfaceView)FindViewById(Resource.Id.surface_two);
            tipTv                = (TextView)FindViewById(Resource.Id.tip_tv);
            detectDurationTv     = (TextView)FindViewById(Resource.Id.detect_duration_tv);
            rgbLivenssDurationTv = (TextView)FindViewById(Resource.Id.rgb_liveness_duration_tv);
            rgbLivenessScoreTv   = (TextView)FindViewById(Resource.Id.rgb_liveness_score_tv);
            irLivenssDurationTv  = (TextView)FindViewById(Resource.Id.ir_liveness_duration_tv);
            irLivenessScoreTv    = (TextView)FindViewById(Resource.Id.ir_liveness_score_tv);
            testIv               = (ImageView)FindViewById(Resource.Id.test_iv);
            mCameraNum           = Android.Hardware.Camera.NumberOfCameras;
            if (mCameraNum != 2)
            {
                Toast.MakeText(this, "未检测到2个摄像头", ToastLength.Long).Show();
                return;
            }
            else
            {
                SurfaceView[] surfaViews = new SurfaceView[mCameraNum];
                mPreview    = new Preview[mCameraNum];
                mCamera     = new Android.Hardware.Camera[mCameraNum];
                mPreview[0] = new Preview(this, surface_one);
                mPreview[1] = new Preview(this, surface_two);
            }

            //        for (int i = 0; i < mCameraNum; i++) {
            //            surfaViews[i] = new SurfaceView(this);
            //            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            //                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
            //            // lp.setMargins(10, 10, 10, 10);
            //            surfaViews[i].setLayoutParams(lp);
            //            ((LinearLayout) FindViewById(Resource.Id.camera_layout)).addView(surfaViews[i]);
            //
            //            mPreview[i] = new Preview(this, surfaViews[i]);
            //            mPreview[i].setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            //            ((RelativeLayout) FindViewById(Resource.Id.layout)).addView(mPreview[i]);
            //        }
        }
        public CustomCameraView(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            this._activity = (Activity)context;

            if (CustomCameraInstance.CustomCameraView != null)
            {
                // set properties, otherwise they will be cleared
                _selectedCamera    = CustomCameraInstance.CustomCameraView.SelectedCamera;
                _cameraOrientation = CustomCameraInstance.CustomCameraView.CameraOrientation;
            }

            var _textureView = new TextureView(context);

            _textureView.SurfaceTextureListener = this;
            AddView(_textureView);

            // make this view available in the PCL
            CustomCameraInstance.CustomCameraView = this;
        }
        public void SetupUserInterface(int height, int width)
        {
            _activity = this.Context as Activity;
            if ((_view = _activity?.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false)) == null)
            {
                return;
            }
            var cameraView = _view.FindViewById <FrameLayout>(Resource.Id.cameraView);
            var parameters = cameraView.LayoutParameters;

            parameters.Height = height;
            parameters.Height = width;
            _cameraType       = CameraFacing.Front;

            this.AddView(_view);

            _textureView = _view.FindViewById <TextureView>(Resource.Id.textureView);
            _textureView.SurfaceTextureListener = this;
        }
Beispiel #24
0
        protected override void Dispose(bool disposeManagedResources)
        {
            base.Dispose(disposeManagedResources);

            if (_vertexBuffer != null && _indexBuffer != null)
            {
                _vertexBuffer.Dispose();
                _vertexBuffer = null;
                _indexBuffer.Dispose();
                _indexBuffer = null;
            }

            textureSet.Dispose();
            textureSet = null;
            textureView.Dispose();
            textureView = null;
            texture.Dispose();
            texture = null;
        }
Beispiel #25
0
        public void Update(ResourceLayout TexLayout, int W, int H)
        {
            if (Width != W || Height != H)
            {
                Tex?.Dispose();
                TexView?.Dispose();

                Width  = W;
                Height = H;

                TextureDescription Desc = new TextureDescription((uint)W, (uint)H, 1, 1, 1, PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.Sampled, TextureType.Texture2D);
                Tex     = Fact.CreateTexture(Desc);
                TexView = Fact.CreateTextureView(Tex);

                SamplerDescription SamplerDesc = new SamplerDescription(SamplerAddressMode.Clamp, SamplerAddressMode.Clamp, SamplerAddressMode.Clamp,
                                                                        SamplerFilter.MinPoint_MagPoint_MipPoint, null, 0, 0, 0, 0, SamplerBorderColor.OpaqueBlack);
                TexSampler = Fact.CreateSampler(SamplerDesc);
            }
        }
Beispiel #26
0
        private void CreateTexture()
        {
            var factory = _device.ResourceFactory;

            _texture?.Dispose();
            _texture = factory.CreateTexture(TextureDescription.Texture2D(
                                                 (uint)_size.Width, (uint)_size.Height,
                                                 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));
            _textureView?.Dispose();
            _textureView = factory.CreateTextureView(_texture);

            ResourceSet?.Dispose();
            ResourceSet = factory.CreateResourceSet(new ResourceSetDescription(
                                                        ResourceLayout, _textureView, _sampler
                                                        ));

            _surface?.Dispose();
            _surface = new ImageSurface(Format.Argb32, _size.Width, _size.Height);
        }
Beispiel #27
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var b = savedInstanceState ?? Intent.Extras;

            id    = b.GetInt(ExtraId);
            front = b.GetInt(ExtraFront);

            SetContentView(Resource.Layout.CameraLayout);

            cameraType = (CameraFacing)front;

            takePhotoButton        = FindViewById <Button>(Resource.Id.takePhotoButton);
            takePhotoButton.Click += TakePhotoButtonTapped;

            textureView = FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;
        }
Beispiel #28
0
        void SetupUserInterface()
        {
            activity   = this.Context as Activity;
            view       = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
            cameraType = CameraFacing.Back;

            textureView = view.FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;

            OCR_textView     = view.FindViewById <TextView>(Resource.Id.myOCR_TextView);
            OCR_Rectangle    = view.FindViewById <ImageView>(Resource.Id.btn_capture_photo);
            OCR_Top_Left     = view.FindViewById <ImageView>(Resource.Id.Top_Left_photo);
            OCR_Top_Right    = view.FindViewById <ImageView>(Resource.Id.Top_Right_photo);
            OCR_Bottom_Left  = view.FindViewById <ImageView>(Resource.Id.Bottom_Left_photo);
            OCR_Bottom_Right = view.FindViewById <ImageView>(Resource.Id.Bottom_Right_photo);

            Canvas canvas = textureView.LockCanvas();
            Paint  paint;

            paint       = new Paint();
            paint.Color = Android.Graphics.Color.Red;
            paint.SetStyle(Paint.Style.Stroke);
            paint.StrokeWidth = 2f;
            Rect r = new Rect((int)100, (int)100, (int)200, (int)200);
            // canvas.DrawRect(r, paint);



            var absolutePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;

            if (!Directory.Exists(absolutePath + "/tessdata"))
            {
                Directory.CreateDirectory(absolutePath + "/tessdata");
            }
            if (!File.Exists(absolutePath + "/tessdata/eng.traineddata"))
            {
                string destPath = absolutePath + "/tessdata/eng.traineddata";
                using (var source = activity.Assets.Open("eng.traineddata"))
                    using (var dest = File.OpenWrite(destPath))
                        source.CopyTo(dest);
            }
        }
Beispiel #29
0
        public void Render(GraphicsDevice gd, CommandList cl, SceneContext sc, RenderPasses renderPass, IRenderable renderable)
        {
            ITextureManager      textureManager = Resolve <ITextureManager>();
            IDeviceObjectManager dom            = Resolve <IDeviceObjectManager>();
            // float depth = gd.IsDepthRangeZeroToOne ? 0 : 1;
            var sprite    = (MultiSprite)renderable;
            var shaderKey = new SpriteShaderKey(sprite);

            sprite.PipelineId = shaderKey.GetHashCode();

            //if (!shaderKey.UseArrayTexture)
            //    return;

            cl.PushDebugGroup($"Sprite:{sprite.Key.Texture.Name}:{sprite.Key.RenderOrder}");

            var uniformInfo = new SpriteUniformInfo {
                Flags = sprite.Key.Flags
            };

            cl.UpdateBuffer(_uniformBuffer, 0, uniformInfo);

            if (sc.PaletteView == null)
            {
                return;
            }

            TextureView textureView    = textureManager?.GetTexture(sprite.Key.Texture);
            var         resourceSet    = dom.Get <ResourceSet>((sprite, textureView));
            var         instanceBuffer = dom.Get <DeviceBuffer>((sprite, sprite));

            cl.SetPipeline(_pipelines[shaderKey]);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vertexBuffer);
            cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            cl.SetVertexBuffer(1, instanceBuffer);

            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, depth, depth));
            cl.DrawIndexed((uint)Indices.Length, (uint)sprite.ActiveInstances, 0, 0, 0);
            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, 0, 1));
            cl.PopDebugGroup();
        }
Beispiel #30
0
        void SetupUserInterface()
        {
            mainLayout = new RelativeLayout(Context);

            //RelativeLayout.LayoutParams mainLayoutParams = new RelativeLayout.LayoutParams(
            //	RelativeLayout.LayoutParams.MatchParent,
            //	RelativeLayout.LayoutParams.MatchParent);
            //mainLayout.LayoutParameters = mainLayoutParams;

            liveView = new TextureView(Context);

            RelativeLayout.LayoutParams liveViewParams = new RelativeLayout.LayoutParams(
                400,
                400);
            liveView.LayoutParameters = liveViewParams;
            mainLayout.AddView(liveView);


            AddView(mainLayout);
        }