示例#1
0
 public static void EndFrame()
 {
     GLRecycleBin.AddTextureToDeleteList(InitialColorBuffer);
     InitialColorBuffer = IntPtr.Zero;
     GLRecycleBin.AddTextureToDeleteList(InitialDepthBuffer);
     InitialDepthBuffer = IntPtr.Zero;
 }
示例#2
0
        static void PostDrawObjects(object sender, DrawEventArgs args)
        {
            if (_activeShaderComponents.Count < 1)
            {
                return;
            }

            if (!OpenGL.Initialized)
            {
                OpenGL.Initialize();
            }
            if (!OpenGL.IsAvailable)
            {
                return;
            }

            UpdateContext(args);

            SortComponents();
            using (IDisposable lifetimeObject = PerFrameCache.BeginFrame(args.Display, _activeShaderComponents))
            {
                foreach (var component in _activeShaderComponents)
                {
                    if (component.Hidden)
                    {
                        continue;
                    }

                    if (!GLSLEditorDialog.EditorsOpen && !AnimationTimerEnabled)
                    {
                        string dataType;
                        int    arrayLength;
                        if (component._model.TryGetUniformType("_time", out dataType, out arrayLength) ||
                            component._model.TryGetUniformType("_date", out dataType, out arrayLength) ||
                            component._model.TryGetUniformType("_mousePosition", out dataType, out arrayLength) ||
                            component._model.TryGetUniformType("_mouseDownPosition", out dataType, out arrayLength) ||
                            component._model.TryGetUniformType("_mouseState", out dataType, out arrayLength))
                        {
                            AnimationTimerEnabled = true;
                        }
                    }

                    component._model.Draw(args.Display, component);
                }
            }
            GLRecycleBin.Recycle();
            _activeShaderComponents.Clear();
        }
示例#3
0
        public static IDisposable BeginFrame(Rhino.Display.DisplayPipeline display, List <GLShaderComponentBase> components)
        {
            // check to see if any components use _colorBuffer or _depthBuffer
            bool usesInitialColorBuffer = false;
            bool usesInitialDepthBuffer = false;

            foreach (var component in components)
            {
                if (!usesInitialColorBuffer && component._model.TryGetUniformType("_colorBuffer", out string dataType, out int arrayLength))
                {
                    usesInitialColorBuffer = true;
                }
                if (!usesInitialDepthBuffer && component._model.TryGetUniformType("_depthBuffer", out dataType, out arrayLength))
                {
                    usesInitialDepthBuffer = true;
                }
            }
            if (usesInitialColorBuffer)
            {
                IntPtr texture2dPtr = Rhino7NativeMethods.RhTexture2dCreate();
                Rhino7NativeMethods.RhTexture2dCapture(display, texture2dPtr, Rhino7NativeMethods.CaptureFormat.kRGBA);
                InitialColorBuffer = texture2dPtr;
            }
            if (usesInitialDepthBuffer)
            {
                IntPtr texture2dPtr = Rhino7NativeMethods.RhTexture2dCreate();
                Rhino7NativeMethods.RhTexture2dCapture(display, texture2dPtr, Rhino7NativeMethods.CaptureFormat.kDEPTH24);
                InitialDepthBuffer = texture2dPtr;
            }

            foreach (var texture in _componentSamplers.Values)
            {
                GLRecycleBin.AddTextureToDeleteList(texture);
            }
            _componentSamplers.Clear();

            // figure out list of per component depth and color textures that need to be created/retrieved
            foreach (var component in components)
            {
                string[] samplers = component._model.GetUniformsAndAttributes(0).GetComponentSamplers();
                foreach (var sampler in samplers)
                {
                    _componentSamplers[sampler.ToLowerInvariant()] = IntPtr.Zero;
                }
            }

            return(new PerFrameLifetimeObject());
        }