コード例 #1
0
ファイル: PositionTexture.cs プロジェクト: tpb3d/TPB3D
        public static void Draw(BeginMode beginMode, PositionTexture[] vertexData, uint handleTexture)
        {
            int primativeCount;
            switch (beginMode)
            {
                case BeginMode.Triangles: primativeCount = vertexData.Length / 3; break;
                case BeginMode.TriangleStrip: primativeCount = vertexData.Length - 2; break;
                default: throw new ArgumentException();
            }
            if (primativeCount == 0) return;


            GL.ActiveTexture(TextureUnit.Texture0);
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, handleTexture);
            
            GL.EnableClientState(EnableCap.VertexArray);

            GL.ClientActiveTexture(TextureUnit.Texture0);
            GL.EnableClientState(EnableCap.TextureCoordArray);

            shader.Use();
            shader.SetSamplerUniform("sampler0", 0);

            unsafe
            {
                fixed (float* pData = &vertexData[0].x)
                {
                    GL.VertexPointer(3, VertexPointerType.Float, PositionTexture.stride, (IntPtr)pData);
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, PositionTexture.stride, (IntPtr)(pData + 3));

                    GL.DrawArrays(beginMode, 0, vertexData.Length);
                }
            }

            GL.DisableClientState(EnableCap.VertexArray);
            GL.DisableClientState(EnableCap.TextureCoordArray);

            //GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            //GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

            GL.Disable(EnableCap.Texture2D);
        }
コード例 #2
0
ファイル: BaseFrame.cs プロジェクト: tpb3d/TPB3D
        private void UpdateFrameBuffer()
        {
            int texWidth = Width + 1;
            int texHeight = Height + titleRectangle.Height + 1;
            
            if(Extentions.IsAvailable(Extentions.ArbTextureNonPowerOfTwo) == false)
            {
                texWidth = (int)Math.Pow(2, Math.Ceiling(Math.Log(texWidth, 2)));
                texHeight = (int)Math.Pow(2, Math.Ceiling(Math.Log(texHeight, 2)));
            }

			int maxTextureSize;
			GL.GetInteger(GetPName.MaxTextureSize, out maxTextureSize);

            if (texWidth > maxTextureSize) texWidth = maxTextureSize;
            if (texHeight > maxTextureSize) texHeight = maxTextureSize;

			bool requiresSquareTexture = false; //TODO Find the proper cap to test.
            if (requiresSquareTexture)
            {
                texWidth = texHeight = Math.Max(texWidth, texHeight);
            }
            
            if (frameBuffer == null || frameBuffer.width != texWidth || frameBuffer.height != texHeight)
            {
            	SafeDispose<FrameBuffer>(ref frameBuffer);
               	frameBuffer = new FrameBuffer(texWidth, texHeight);
            	modelViewProjection = Matrix4Helper.CreateOrthographicProjection(0, texWidth, 0, texHeight, 0, 1);
            }

			int top = titleRectangle.Y;
			int left = titleRectangle.X;
			int right = titleRectangle.X + texWidth - 1;
			int bottom = titleRectangle.Y + texHeight - 1;

            frameBufferQuad[0] = new PositionTexture(left,  top,    0, 0, 1);
            frameBufferQuad[1] = new PositionTexture(left,  bottom, 0, 0, 0);
            frameBufferQuad[2] = new PositionTexture(right, top,    0, 1, 1);
            frameBufferQuad[3] = new PositionTexture(right, bottom, 0, 1, 0);
        }