예제 #1
0
        /// <summary>
        /// Construct a control display
        /// </summary>
        /// <param name="items">Items to store GL data to</param>
        /// <param name="win">GLWindowControl to hook to</param>
        /// <param name="mc">Matrix Calc to use</param>
        /// <param name="depthtest">Enable depth test</param>
        /// <param name="startz">Start Z for nearest top level window</param>
        /// <param name="deltaz">Delta Z between each top level window</param>
        /// <param name="arbbufferid">ARB buffer to use for texture bindless storage</param>
        public GLControlDisplay(GLItemsList items, GLWindowControl win, GLMatrixCalc mc,
                                bool depthtest  = true,             // do depth testing or not
                                float startz    = 0.001f,           // z for the deepest window (only will apply if depth testing
                                float deltaz    = 0.001f,           // delta betwwen them
                                int arbbufferid = 10
                                ) : base("displaycontrol", new Rectangle(0, 0, mc.ScreenCoordMax.Width, mc.ScreenCoordMax.Height))
        {
            glwin      = win;
            MatrixCalc = mc;
            context    = GLStatics.GetContext();

            this.items = items;

            vertexes = items.NewBuffer();

            vertexarray = items.NewVertexArray();
            vertexes.Bind(vertexarray, 0, 0, vertexesperentry * sizeof(float));                            // bind to 0, from 0, 2xfloats. Must bind after vertexarray is made as its bound during construction

            vertexarray.Attribute(0, 0, vertexesperentry, OpenTK.Graphics.OpenGL4.VertexAttribType.Float); // bind 0 on attr 0, 2 components per vertex

            GLRenderState rc = GLRenderState.Tri();

            rc.PrimitiveRestart = 0xff;
            rc.DepthTest        = depthtest;

            this.startz = startz;
            this.deltaz = deltaz;

            ri = new GLRenderableItem(PrimitiveType.TriangleStrip, rc, 0, vertexarray); // create a renderable item
            ri.CreateRectangleElementIndexByte(items.NewBuffer(), 255 / 5);             // note this limits top level controls number to 255/5.
            ri.DrawCount = 0;                                                           // nothing to draw at this point

            shader = new GLShaderPipeline(new GLPLVertexShaderScreenTexture(), new GLPLFragmentShaderBindlessTexture(arbbufferid, true, discardiftransparent: true));
            items.Add(shader);

            textures = new Dictionary <GLBaseControl, GLTexture2D>();
            size     = new Dictionary <GLBaseControl, Size>();
            visible  = new Dictionary <GLBaseControl, bool>();

            texturebinds = items.NewBindlessTextureHandleBlock(arbbufferid);

            glwin.MouseMove        += Gc_MouseMove;
            glwin.MouseClick       += Gc_MouseClick;
            glwin.MouseDoubleClick += Gc_MouseDoubleClick;
            glwin.MouseDown        += Gc_MouseDown;
            glwin.MouseUp          += Gc_MouseUp;
            glwin.MouseEnter       += Gc_MouseEnter;
            glwin.MouseLeave       += Gc_MouseLeave;
            glwin.MouseWheel       += Gc_MouseWheel;
            glwin.KeyDown          += Gc_KeyDown;
            glwin.KeyUp            += Gc_KeyUp;
            glwin.KeyPress         += Gc_KeyPress;
            glwin.Resize           += Gc_Resize;
            glwin.Paint            += Gc_Paint;

            suspendLayoutCount = 0;
        }