コード例 #1
0
        public void on_glTexImage2D(int level, int internalformat,
                                    int width, int height, int border, uint format, uint type, byte[] pixels, int offset)
        {
            KPMipmapLevel mip = m_pMipmaps[level];

            mip.reset();

            mip.IsCompressed = 0;

            mip.Format = internalformat;
            mip.Width  = width;
            mip.Height = height;

            mip.Type = type;

            int imageSize = mip.calculateSize();

            if (imageSize > 0)
            {
                mip.Pixels = new byte[imageSize];
                Utils.memcpy(mip.Pixels, 0, pixels, offset, imageSize);
            }

            mip.HasData = true;
        }
コード例 #2
0
        public override void fromMessage(KPMessage msg)
        {
            clearData();

            MyBinStream stream = new MyBinStream(msg.Data);

            m_id      = stream.readUInt();
            m_texType = (KPTextureType)stream.readInt();

            int mipmapCount = stream.readInt();

            for (int i = 0; i < mipmapCount; i++)
            {
                int level = stream.readInt();
                Utils.assert(level >= 0 && level < MAX_MIPMAP_LEVEL_NUMBER);
                KPMipmapLevel mip = m_pMipmaps[level];

                mip.reset();

                mip.Width        = stream.readInt();
                mip.Height       = stream.readInt();
                mip.IsCompressed = stream.readByte();
                mip.Format       = stream.readInt();
                mip.Type         = stream.readUInt();

                byte hasPixel = stream.readByte();
                if (hasPixel == 1)
                {
                    int mipSize = mip.calculateSize();
                    if (mipSize > 0)
                    {
                        mip.Pixels = new byte[mipSize];
                        stream.readBytes(mip.Pixels, 0, mipSize);
                    }
                }

                mip.HasData = true;
            }

            stream.close();
        }
コード例 #3
0
        private void showLevel(int level)
        {
            KPMipmapLevel mip = m_tex.Mipmaps[level];

            if (m_bitmaps[level] == null)
            {
                if (mip.Pixels == null)
                {
                    m_bitmaps[level] = global::KataProfiler.Properties.Resources.not_recorded;
                }
                else
                {
                    switch ((uint)mip.Format)
                    {
                    case gl2.GL_RGBA:
                    {
                        switch (mip.Type)
                        {
                        case gl2.GL_UNSIGNED_BYTE:
                            m_bitmaps[level] = Utils.makeBitmap_RGBA(mip.Width, mip.Height, mip.Pixels, 0, false);
                            break;

                        case gl2.GL_UNSIGNED_SHORT_4_4_4_4:
                            m_bitmaps[level] = Utils.makeBitmap_RGBA4444(mip.Width, mip.Height, mip.Pixels, 0, false);
                            break;

                        case gl2.GL_UNSIGNED_SHORT_5_5_5_1:
                            m_bitmaps[level] = Utils.makeBitmap_RGBA5551(mip.Width, mip.Height, mip.Pixels, 0, false);
                            break;

                        default:
                            Utils.assert(false);
                            break;
                        }

                        break;
                    }

                    case gl2.GL_RGB:
                    {
                        switch (mip.Type)
                        {
                        case gl2.GL_UNSIGNED_BYTE:
                            m_bitmaps[level] = Utils.makeBitmap_RGB(mip.Width, mip.Height, mip.Pixels, 0, false);
                            break;

                        case gl2.GL_UNSIGNED_SHORT_5_6_5:
                            m_bitmaps[level] = Utils.makeBitmap_RGB565(mip.Width, mip.Height, mip.Pixels, 0, false);
                            break;

                        default:
                            Utils.assert(false);
                            break;
                        }

                        break;
                    }

                    case gl2.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
                    case gl2.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
                        m_bitmaps[level] = Utils.makeBitmap_PVR(0, mip.Width, mip.Height, mip.Pixels);
                        break;

                    case gl2.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
                    case gl2.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
                        m_bitmaps[level] = Utils.makeBitmap_PVR(1, mip.Width, mip.Height, mip.Pixels);
                        break;

                    case gl2.GL_ETC1_RGB8_OES:
                        m_bitmaps[level] = Utils.makeBitmap_ETC(mip.Width, mip.Height, mip.Pixels);
                        break;

                    case gl2.GL_COMPRESSED_RGB8_ETC2:
                    case gl2.GL_COMPRESSED_SRGB8_ETC2:
                    case gl2.GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
                    case gl2.GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
                    case gl2.GL_COMPRESSED_RGBA8_ETC2_EAC:
                    case gl2.GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
                        m_bitmaps[level] = Utils.makeBitmap_ETC2((uint)mip.Format, mip.Width, mip.Height, mip.Pixels);
                        break;

                    case gl2.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
                    case gl2.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
                        m_bitmaps[level] = Utils.makeBitmap_DXT(1, mip.Width, mip.Height, mip.Pixels);
                        break;

                    case gl2.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
                        m_bitmaps[level] = Utils.makeBitmap_DXT(3, mip.Width, mip.Height, mip.Pixels);
                        break;

                    case gl2.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
                        m_bitmaps[level] = Utils.makeBitmap_DXT(3, mip.Width, mip.Height, mip.Pixels);
                        break;

                    // Don't support
                    //case gl2.GL_DEPTH_COMPONENT: // TODO
                    //{
                    //    if (mip.Type == gl2.GL_UNSIGNED_SHORT) // 16 bit depth
                    //    {
                    //    }
                    //    else if (mip.Type == gl2.GL_UNSIGNED_INT) // 32 bit depth
                    //    {
                    //    }
                    //    break;
                    //}

                    case gl2.GL_ALPHA:
                        m_bitmaps[level] = Utils.makeBitmap_ALPHA(mip.Width, mip.Height, mip.Pixels, 0, false);
                        break;

                    case gl2.GL_LUMINANCE:
                        m_bitmaps[level] = Utils.makeBitmap_LUMINANCE(mip.Width, mip.Height, mip.Pixels, 0, false);
                        break;

                    case gl2.GL_LUMINANCE_ALPHA:
                        m_bitmaps[level] = Utils.makeBitmap_LUMINANCE_ALPHA(mip.Width, mip.Height, mip.Pixels, 0, false);
                        break;

                    default:
                        Utils.assert(false);
                        break;
                    }                     // switch
                }
            }

            m_currentLevel = level;

            pictureBox.Image  = m_bitmaps[level];
            pictureBox.Width  = mip.Width;
            pictureBox.Height = mip.Height;

            labelSize.Text   = mip.Width + " x " + mip.Height;
            labelFormat.Text = mip.FormatName;
            int imageSize = mip.calculateSize();

            labelLength.Text = Utils.getDynamicSize(mip.calculateSize());
        }
コード例 #4
0
ファイル: FormMain.cs プロジェクト: mowenli/KataProfiler
        private void listBoxRenderCommands_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = listBoxRenderCommands.SelectedIndex;

            if (index < 0)
            {
                return;
            }

            int lastIndex = listBoxRenderCommands.Items.Count - 2;

            if (index <= lastIndex)
            {
                trackBarSS.Value = 1 + (int)Math.Round(99.0f * (float)index / (float)lastIndex);
            }
            else
            {
                trackBarSS.Value = 100;
            }

            KPClient client = KPClient.getInstance();

            KPMessage[] listCommands = client.ListCommands;
            int[]       listIndexes  = client.ListRenderCommandIndexes;

            //=============================================================================================
            // Fill the listBoxSubCommands
            //=============================================================================================
            listBoxSubCommands.Items.Clear();

            int start = index == 0 ? 0 : listIndexes[index - 1] + 1;

            int subCommandsCount = listIndexes[index] - start;

            string[] arr = null;
            if (subCommandsCount > 0)
            {
                arr = new string[subCommandsCount];
            }
            for (int i = start; i < listIndexes[index]; i++)
            {
                arr[i - start] = listCommands[i].toString();
            }
            if (arr != null)
            {
                listBoxSubCommands.Items.AddRange(arr);
            }

            listBoxSubCommands.SelectedIndex = -1;

            //=============================================================================================
            // Show screen shot and vertex data
            //=============================================================================================
            KPMessage     cmd  = client.ListCommands[listIndexes[index]];
            KPMessageType type = (KPMessageType)cmd.Type;

            tabPageVertexData.Controls.Clear();
            List <uint> list_ArrayBuffer_VboId = null;

            bool isDrawnCommand = false;

            if (type == KPMessageType.KMT_glDrawElements || type == KPMessageType.KMT_glDrawArrays ||
                type == KPMessageType.KMT_glClear)
            {
                #region Show screen shot
                {
                    Bitmap      bmp    = null;
                    MyBinStream stream = new MyBinStream(cmd.Data);

                    if (type == KPMessageType.KMT_glDrawElements)
                    {
                        stream.readUInt();                        // fbo
                        stream.readUInt();                        // mode
                        stream.readInt();                         // count
                        stream.readUInt();                        // type
                        stream.readInt();                         // indices
                        stream.readFloat();                       // zNear
                        stream.readFloat();                       // zFar
                    }
                    else if (type == KPMessageType.KMT_glDrawArrays)
                    {
                        stream.readUInt();                        // fbo
                        stream.readUInt();                        // mode
                        stream.readInt();                         // first
                        stream.readInt();                         // count
                        stream.readFloat();                       // zNear
                        stream.readFloat();                       // zFar
                    }
                    else if (type == KPMessageType.KMT_glClear)
                    {
                        stream.readUInt();                         // fbo
                        stream.readUInt();                         // mask
                    }

                    m_screenShotWidth  = stream.readInt();
                    m_screenShotHeight = stream.readInt();

                    if (m_bitmapPool.ContainsKey(index))
                    {
                        bmp = m_bitmapPool[index];
                    }
                    else
                    {
                        int widthScaled  = stream.readInt();
                        int heightScaled = stream.readInt();

                        int imageLen = stream.readInt();
                        int curPos   = stream.CurrentPosition;
                        //bmp = Utils.makeBitmap_RGBA(widthScaled, heightScaled, cmd.Data, curPos, true);
                        bmp = Utils.makeBitmap_RGB(widthScaled, heightScaled, cmd.Data, curPos, true);

                        m_bitmapPool.Add(index, bmp);
                    }
                    stream.close();

                    pictureBoxScreenShot.Dock = DockStyle.None;

                    zoomSS();

                    pictureBoxScreenShot.Image = bmp;
                }
                #endregion

                #region Show vertex data
                if (type == KPMessageType.KMT_glDrawElements || type == KPMessageType.KMT_glDrawArrays)
                {
                    isDrawnCommand = true;

                    TabControl tabControlVertexData = null;

                    if (m_vertexDataTabControlPool.ContainsKey(index))
                    {
                        tabControlVertexData   = m_vertexDataTabControlPool[index];
                        list_ArrayBuffer_VboId = m_inUseVboIdPool[index];
                    }
                    else
                    {
                        list_ArrayBuffer_VboId = new List <uint>();

                        tabControlVertexData               = new TabControl();
                        tabControlVertexData.Dock          = System.Windows.Forms.DockStyle.Fill;
                        tabControlVertexData.Font          = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                        tabControlVertexData.Location      = new System.Drawing.Point(3, 4);
                        tabControlVertexData.Margin        = new System.Windows.Forms.Padding(3, 4, 3, 4);
                        tabControlVertexData.Name          = "tabControlVertexData";
                        tabControlVertexData.SelectedIndex = 0;

                        #region

                        MyBinStream stream = new MyBinStream(cmd.Data);

                        int count, first;

                        if (type == KPMessageType.KMT_glDrawElements)
                        {
                            stream.readUInt();        // fbo
                            stream.readUInt();        // mode
                            count = stream.readInt(); // count
                            stream.readUInt();        // type
                            stream.readInt();         // indices
                        }
                        else                          // type == KPMessageType.KMT_glDrawArrays
                        {
                            stream.readUInt();        // fbo
                            stream.readUInt();        // mode
                            first = stream.readInt(); // first
                            count = stream.readInt(); // count
                        }
                        stream.readFloat();           // zNear
                        stream.readFloat();           // zFar

                        int width        = stream.readInt();
                        int height       = stream.readInt();
                        int widthScaled  = stream.readInt();
                        int heightScaled = stream.readInt();
                        int imageLen     = stream.readInt();

                        stream.skip(imageLen);

                        int attCount = stream.readInt();

                        tabControlVertexData.TabPages.Clear();

                        for (int i = 0; i < attCount; i++)
                        {
                            #region Process attribute

                            byte enableVertexAttribArray = stream.readByte();

                            int location   = stream.readInt();
                            int components = stream.readInt();

                            TabPage tp = new TabPage("Loc " + location +
                                                     (enableVertexAttribArray == 0 ? " (non-array)" : "")
                                                     );

                            ListView view = new ListView();
                            #region
                            view.Dock          = DockStyle.Fill;
                            view.BorderStyle   = BorderStyle.Fixed3D;
                            view.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
                            view.FullRowSelect = true;
                            view.GridLines     = true;
                            view.MultiSelect   = false;
                            view.ShowGroups    = false;
                            view.View          = View.Details;

                            ColumnHeader[] columnHeaders = new ColumnHeader[components + 1];
                            for (int k = 0; k <= components; k++)
                            {
                                columnHeaders[k]      = new ColumnHeader();
                                columnHeaders[k].Text = m_sColsName[k];
                            }
                            view.Columns.AddRange(columnHeaders);
                            #endregion

                            if (enableVertexAttribArray == 0)
                            {
                                string[] row = new string[components + 1];
                                row[0] = "#";
                                for (int k = 1; k <= components; k++)
                                {
                                    row[k] = stream.readFloat().ToString();
                                }
                                ListViewItem item = new ListViewItem(row);
                                view.Items.Add(item);
                            }
                            else
                            {
                                byte normalized = stream.readByte();
                                if (normalized == 1)
                                {
                                    tp.Text += " (nm)";
                                }

                                uint vboId = stream.readUInt();
                                list_ArrayBuffer_VboId.Add(vboId);

                                uint dataType = stream.readUInt();

                                ListViewItem[] itemArray = null;
                                if (count > 0)
                                {
                                    itemArray = new ListViewItem[count];
                                }

                                #region
                                for (int j = 0; j < count; j++)
                                {
                                    string[] row = new string[components + 1];

                                    row[0] = j.ToString();

                                    for (int k = 1; k <= components; k++)
                                    {
                                        switch (dataType)
                                        {
                                        case gl2.GL_BYTE:
                                        {
                                            sbyte val = stream.readSByte();
                                            row[k] = val.ToString();
                                            if (normalized == 1)
                                            {
                                                row[k] += " (" + ((val + 128.0f) / 255.0f * 2.0f - 1.0f) + ")";
                                            }
                                            break;
                                        }

                                        case gl2.GL_UNSIGNED_BYTE:
                                        {
                                            byte val = stream.readByte();
                                            row[k] = val.ToString();
                                            if (normalized == 1)
                                            {
                                                row[k] += " (" + (val / 255.0f) + ")";
                                            }
                                            break;
                                        }

                                        case gl2.GL_SHORT:
                                        {
                                            Int16 val = stream.readShort();
                                            row[k] = val.ToString();
                                            if (normalized == 1)
                                            {
                                                row[k] += " (" + ((val + 32768.0f) / 65535.0f * 2.0f - 1.0f) + ")";
                                            }
                                            break;
                                        }

                                        case gl2.GL_UNSIGNED_SHORT:
                                        {
                                            UInt16 val = stream.readUShort();
                                            row[k] = val.ToString();
                                            if (normalized == 1)
                                            {
                                                row[k] += " (" + (val / 65535.0f) + ")";
                                            }
                                            break;
                                        }

                                        case gl2.GL_FLOAT:
                                        {
                                            row[k] = stream.readFloat().ToString();
                                            break;
                                        }

                                        case gl2.GL_FIXED:
                                        {
                                            //Utils.assert(false);
                                            row[k] = stream.readInt().ToString();
                                            break;
                                        }
                                        }
                                    }
                                    itemArray[j] = new ListViewItem(row);
                                }
                                #endregion

                                if (itemArray != null)
                                {
                                    view.Items.AddRange(itemArray);
                                }
                            }

                            tp.Controls.Add(view);

                            #endregion

                            tabControlVertexData.TabPages.Add(tp);
                        }

                        stream.close();
                        #endregion

                        m_vertexDataTabControlPool.Add(index, tabControlVertexData);
                        m_inUseVboIdPool.Add(index, list_ArrayBuffer_VboId);
                    }

                    tabPageVertexData.Controls.Add(tabControlVertexData);
                }
                #endregion
            }
            else if (type == KPMessageType.KMT_NONE)
            {
                pictureBoxScreenShot.Width  = 0;
                pictureBoxScreenShot.Height = 0;
                pictureBoxScreenShot.Dock   = DockStyle.Fill;
                pictureBoxScreenShot.Image  = null;
            }

            //=============================================================================================
            // Fill the objects list
            //=============================================================================================
            client.makeStateMachine(listIndexes[index]);

            #region Textures list
            {
                listViewTextures.Items.Clear();

                List <KPTexture> textures = client.CurrentStateMachine.ListTextures;

                int         texSumBytes = 0;
                List <uint> listTexId   = isDrawnCommand ? client.CurrentStateMachine.getDrawingTextures() : new List <uint>();

                ListViewItem[] itemArray = null;
                if (textures.Count > 0)
                {
                    itemArray = new ListViewItem[textures.Count];
                }

                for (int i = 0; i < textures.Count; i++)
                {
                    texSumBytes += textures[i].SizeInBytes;

                    bool inUse = listTexId.Contains(textures[i].Id);

                    KPMipmapLevel mip = textures[i].Mipmaps[0];

                    bool is2n     = Utils.isPowerOf2(mip.Width) && Utils.isPowerOf2(mip.Height);
                    bool isSquare = mip.Width == mip.Height;

                    itemArray[i] = new ListViewItem(new string[] {
                        textures[i].Id.ToString(),
                        mip.Width.ToString(),
                        mip.Height.ToString(),
                        mip.FormatName,
                        textures[i].MipmapCount.ToString(),
                        mip.calculateSize().ToString(),
                        (mip.Width * mip.Height).ToString(),
                        is2n ? "Yes" : "No",
                        isSquare ? "Yes" : "No",
                        textures[i].TexType == KPTextureType.TEX_2D ? "2D" : "Cube",
                        client.CurrentStateMachine.getTexUnitsOfTexId(textures[i].Id),

                        inUse ? "Yes" : "No"
                    });

                    if (inUse)
                    {
                        highlightItem(itemArray[i]);
                    }
                }
                if (itemArray != null)
                {
                    listViewTextures.Items.AddRange(itemArray);
                }

                m_lvicTextures.setColumnIndexToSort(columnHeader_TexInUse.Index);
                listViewTextures.Sort();

                labelTexturesSummary.Text = textures.Count + " texture(s) / " + Utils.getDynamicSize(texSumBytes);

                panelTextures.Visible = true;
            }
            #endregion

            #region Programs list
            {
                listViewPrograms.Items.Clear();

                List <KPProgram> programs    = client.CurrentStateMachine.ListPrograms;
                uint             usingProgId = isDrawnCommand ? client.CurrentStateMachine.CurrentProgId : 0;

                ListViewItem   usingItem = null;
                ListViewItem[] itemArray = null;
                if (programs.Count > 0)
                {
                    itemArray = new ListViewItem[programs.Count];
                }

                for (int i = 0; i < programs.Count; i++)
                {
                    itemArray[i] = new ListViewItem(new string[] {
                        programs[i].Id.ToString(),
                        programs[i].VsId.ToString(),
                        programs[i].FsId.ToString()
                    });

                    if (usingProgId == programs[i].Id)
                    {
                        usingItem = itemArray[i];
                        highlightItem(itemArray[i]);
                    }
                }
                if (itemArray != null)
                {
                    listViewPrograms.Items.AddRange(itemArray);
                }

                if (usingItem != null)
                {
                    listViewPrograms.EnsureVisible(usingItem.Index);
                }

                labelProgramsSummary.Text = programs.Count + " program(s)";

                panelPrograms.Visible = true;
            }
            #endregion

            #region Vbos list
            {
                listViewVbos.Items.Clear();

                List <KPVbo> vbos = client.CurrentStateMachine.ListVbos;

                uint bindingVboId_ElementArrayBuffer = isDrawnCommand ? client.CurrentStateMachine.CurrentVboId_ElementArrayBuffer : 0;

                ListViewItem[] itemArray = null;
                if (vbos.Count > 0)
                {
                    itemArray = new ListViewItem[vbos.Count];
                }

                int sum_Size = 0;

                for (int i = 0; i < vbos.Count; i++)
                {
                    bool inUse_ArrayBuffer = list_ArrayBuffer_VboId == null || !isDrawnCommand ?
                                             false : list_ArrayBuffer_VboId.Contains(vbos[i].Id);

                    bool inUse_ElementArrayBuffer = !isDrawnCommand ? false : bindingVboId_ElementArrayBuffer == vbos[i].Id;

                    sum_Size += vbos[i].Size;

                    itemArray[i] = new ListViewItem(new string[] {
                        vbos[i].Id.ToString(),

                        vbos[i].Size.ToString(),
                        gl2.getString(vbos[i].Usage),

                        inUse_ArrayBuffer || inUse_ElementArrayBuffer ? "Yes" : "No"
                    });

                    if (inUse_ArrayBuffer && inUse_ElementArrayBuffer)
                    {
                        highlightItem(itemArray[i], Color.Red);
                    }
                    else if (inUse_ArrayBuffer)
                    {
                        highlightItem(itemArray[i]);
                    }
                    else if (inUse_ElementArrayBuffer)
                    {
                        highlightItem(itemArray[i], Color.Brown);
                    }
                }

                if (itemArray != null)
                {
                    listViewVbos.Items.AddRange(itemArray);
                }

                m_lvicVbos.setColumnIndexToSort(columnHeader_VboInUse.Index);
                listViewVbos.Sort();

                labelVbosSummary.Text = string.Format("{0} vbo(s) / {1}", vbos.Count, Utils.getDynamicSize(sum_Size));

                panelVbos.Visible = true;
            }
            #endregion

            //Utils.gc();
        }