Beispiel #1
0
        private void BlitFramebuffers(Framebuffer source, Framebuffer destination, BlitMode mode)
        {
            source.BindWithPurpose(FramebufferTarget.ReadFramebuffer);
            GL.FramebufferTexture2D(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, source.TexColor, 0);
            GL.ReadBuffer(ReadBufferMode.ColorAttachment0);

            destination.BindWithPurpose(FramebufferTarget.DrawFramebuffer);
            GL.FramebufferTexture2D(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, destination.TexColor, 0);
            GL.DrawBuffer(DrawBufferMode.ColorAttachment0);

            if (mode == BlitMode.Color)
            {
                GL.BlitFramebuffer(0, 0, source.Width, source.Height, 0, 0, destination.Width, destination.Height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear);
            }
            else if (mode == BlitMode.Depth)
            {
                GL.BlitFramebuffer(0, 0, source.Width, source.Height, 0, 0, destination.Width, destination.Height, ClearBufferMask.DepthBufferBit, BlitFramebufferFilter.Linear);
            }
            else if (mode == BlitMode.ColorAndDepth)
            {
                GL.BlitFramebuffer(0, 0, source.Width, source.Height, 0, 0, destination.Width, destination.Height, ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit, BlitFramebufferFilter.Linear);
            }
        }
        /// <summary>
        /// Parses a CFS file.
        /// </summary>
        private void Parse(byte[] buffer)
        {
            int offset = 0;

            Frame[] frames;
            byte[]  frameData;

            _totalSize = buffer.Length;

            _version = (int)BitConverter.ToInt16(buffer, offset); offset += 2;

            if (_version == 4)
            {
                _frameCount = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                if (_frameCount <= 0)
                {
                    throw new Exception("There is an invalid number of frames: " + _frameCount);
                }

                _animationTime  = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _width          = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _height         = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _rows           = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _columns        = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _lightLength    = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _shadowLength   = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _userDataLength = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                //_compression = (CompressionFlags)buffer[offset]; offset++;
                _maxSolidIndex     = (int)buffer[offset]; offset++;
                _dataSize          = (int)BitConverter.ToInt32(buffer, offset); offset += 4;
                _category          = ASCIIEncoding.ASCII.GetString(buffer, offset, 16); offset += 16;
                _blitMode          = (BlitMode)buffer[offset]; offset++;
                _rowMode           = (RowMode)buffer[offset]; offset++;
                _sortAdjust        = (int)BitConverter.ToInt16(buffer, offset); offset += 2;
                _sortTransform     = (SortTransform)buffer[offset]; offset++;
                _userPaletteStart  = (int)buffer[offset]; offset++;
                _userPaletteLength = (int)buffer[offset]; offset++;
                _description       = ASCIIEncoding.ASCII.GetString(buffer, offset, 48); offset += 48;

                _unknownData = new byte[32];
                Buffer.BlockCopy(buffer, offset, _unknownData, 0, _unknownData.Length);
                offset += _unknownData.Length;

                _palette = new int[256];
                for (int i = 0; i < _palette.Length; i++)
                {
                    int argb;

                    argb  = BitConverter.ToInt32(buffer, offset); offset += 4;
                    argb |= unchecked ((int)0xFF000000);

                    _palette[i] = argb;
                }

                frames = new Frame[_frameCount];

                // Read all the frame meta info
                for (int i = 0; i < _frameCount; i++)
                {
                    frames[i] = ReadFrameInfo(buffer, offset);
                    offset   += 12;

                    frames[i].Row    = i / _columns;
                    frames[i].Column = i - (frames[i].Row * _columns);
                }

                // Read the user data
                if (_userDataLength > 0)
                {
                    _userData = new byte[_userDataLength];
                    Array.Copy(buffer, offset, _userData, 0, _userDataLength);

                    offset += _userDataLength;
                }
                else
                {
                    _userData = new byte[] { };
                }

                _data = new byte[_width * _height * _frameCount];

                // Decode the frames
                foreach (Frame frame in frames)
                {
                    //frameData = DecodeFrameData(frame, buffer, offset);

                    // TODO: finish me
                }

                //DecodeFrameData(frames[17], buffer, offset);



                //foreach (Frame frame in frames) {
                //    DecodeFrameData(frame, buffer, offset);
                //}
                //frameData = DecodeFrameData(frames[0], buffer, offset);
            }
            else
            {
                throw new Exception("Unknown file version: " + _version);
            }
        }