public static string makeMatrixString(MyBinStream stream, int count, int size) { string res = ""; for (int i = 0; i < count; i++) { res += "["; for (int row = 0; row < size; row++) { res += "("; for (int col = 0; col < size; col++) { res += stream.readFloat(); if (col < size - 1) { res += ", "; } } res += ")"; if (row < size - 1) { res += ", "; } } res += "]"; if (i < count - 1) { res += ", "; } } return(res); }
public void on_glUniform4iv(MyBinStream stream) { int location = stream.readInt(); int count = stream.readInt(); if (location < 0 || count <= 0) { return; } for (int i = 0; i < m_uniformsCount; i++) { Var uni = m_uniforms[i]; if (uni.Location == location) { var res = ""; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1}, {2}, {3})", stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt()); if (j < count - 1) { res += ", "; } } uni.Value = res; break; } } }
public void fromBytes(byte[] bytes, int offset, int count) { MyBinStream stream = new MyBinStream(bytes, offset, count); this.fromStream(stream); stream.close(); }
public override void fromMessage(Message msg) { Utils.assert(msg.Type == (int)KPMessageType.KMT_OBJECT_PROGRAM); clearData(); MyBinStream stream = new MyBinStream(msg.Data); this.fromStream(stream); stream.close(); }
public override void fromMessage(KPMessage msg) { Utils.assert(msg.Length >= 4 * 2); clearData(); MyBinStream stream = new MyBinStream(msg.Data); m_id = stream.readUInt(); m_type = stream.readUInt(); m_source = stream.readString(); stream.close(); }
public override void fromMessage(Message msg) { clearData(); MyBinStream stream = new MyBinStream(msg.Data); m_id = stream.readUInt(); m_size = stream.readInt(); m_usage = stream.readUInt(); m_dataAddress = stream.readInt(); stream.close(); }
public void on_glUniform4i(MyBinStream stream) { int location = stream.readInt(); if (location < 0) { return; } for (int i = 0; i < m_uniformsCount; i++) { Var uni = m_uniforms[i]; if (uni.Location == location) { uni.Value = string.Format("{0}, {1}, {2}, {3}", stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt()); break; } } }
public override void fromMessage(Message 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); Mipmap 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(); }
public void on_glUniformMatrix(MyBinStream stream, int size) { int location = stream.readInt(); int count = stream.readInt(); if (location < 0 || count <= 0) { return; } byte transpose = stream.readByte(); for (int i = 0; i < m_uniformsCount; i++) { Var uni = m_uniforms[i]; if (uni.Location == location) { uni.Value = Utils.makeMatrixString(stream, count, size); break; } } }
private void listBoxRenderCommands_SelectedIndexChanged(object sender, EventArgs e) { int index = listBoxRenderCommands.SelectedIndex; if (index < 0) { return; } int lastIndex = listBoxRenderCommands.Items.Count - 2; Client client = Client.getInstance(); Message[] 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 //============================================================================================= Message 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 gl.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 gl.GL_UNSIGNED_BYTE: { byte val = stream.readByte(); row[k] = val.ToString(); if (normalized == 1) { row[k] += " (" + (val / 255.0f) + ")"; } break; } case gl.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 gl.GL_UNSIGNED_SHORT: { UInt16 val = stream.readUShort(); row[k] = val.ToString(); if (normalized == 1) { row[k] += " (" + (val / 65535.0f) + ")"; } break; } case gl.GL_FLOAT: { row[k] = stream.readFloat().ToString(); break; } case gl.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 <Texture> 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); Mipmap 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 <Program> 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 <Vbo> 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(), gl.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(); }
public void fromStream(MyBinStream stream) { m_id = stream.readUInt(); m_vsId = stream.readUInt(); m_fsId = stream.readUInt(); // m_attributesCount = stream.readInt(); for (int i = 0; i < m_attributesCount; i++) { Var var = m_attributes[i]; var.Location = stream.readInt(); var.Size = stream.readInt(); var.Type = stream.readUInt(); int strLen = stream.readInt(); var.Name = stream.readString(strLen); } // m_uniformsCount = stream.readInt(); for (int i = 0; i < m_uniformsCount; i++) { Var var = m_uniforms[i]; var.Location = stream.readInt(); var.Size = stream.readInt(); var.Type = stream.readUInt(); int strLen = stream.readInt(); var.Name = stream.readString(strLen); int dataLen = stream.readInt(); string res = ""; if (dataLen > 0) { switch (var.Type) { #region FLOAT case gl.GL_FLOAT: { Utils.assert(dataLen % 4 == 0); int count = dataLen / 4; for (int j = 0; j < count; j++) { res += stream.readFloat(); if (j < count - 1) { res += ", "; } } break; } case gl.GL_FLOAT_VEC2: { Utils.assert(dataLen % 8 == 0); int count = dataLen / 8; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1})", stream.readFloat(), stream.readFloat()); if (j < count - 1) { res += ", "; } } break; } case gl.GL_FLOAT_VEC3: { Utils.assert(dataLen % 12 == 0); int count = dataLen / 12; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1}, {2})", stream.readFloat(), stream.readFloat(), stream.readFloat()); if (j < count - 1) { res += ", "; } } break; } case gl.GL_FLOAT_VEC4: { Utils.assert(dataLen % 16 == 0); int count = dataLen / 16; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1}, {2}, {3})", stream.readFloat(), stream.readFloat(), stream.readFloat(), stream.readFloat()); if (j < count - 1) { res += ", "; } } break; } #endregion #region INT, BOOL, SAMPLER case gl.GL_INT: case gl.GL_SAMPLER_2D: case gl.GL_SAMPLER_3D: case gl.GL_SAMPLER_CUBE: case gl.GL_BOOL: { Utils.assert(dataLen % 4 == 0); int count = dataLen / 4; for (int j = 0; j < count; j++) { res += stream.readInt(); if (j < count - 1) { res += ", "; } } break; } case gl.GL_INT_VEC2: case gl.GL_BOOL_VEC2: { Utils.assert(dataLen % 8 == 0); int count = dataLen / 8; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1})", stream.readInt(), stream.readInt()); if (j < count - 1) { res += ", "; } } break; } case gl.GL_INT_VEC3: case gl.GL_BOOL_VEC3: { Utils.assert(dataLen % 12 == 0); int count = dataLen / 12; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1}, {2})", stream.readInt(), stream.readInt(), stream.readInt()); if (j < count - 1) { res += ", "; } } break; } case gl.GL_INT_VEC4: case gl.GL_BOOL_VEC4: { Utils.assert(dataLen % 16 == 0); int count = dataLen / 16; for (int j = 0; j < count; j++) { res += string.Format("({0}, {1}, {2}, {3})", stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt()); if (j < count - 1) { res += ", "; } } break; } #endregion #region MATRIX case gl.GL_FLOAT_MAT2: case gl.GL_FLOAT_MAT3: case gl.GL_FLOAT_MAT4: { int size = (var.Type == gl.GL_FLOAT_MAT2) ? 2 : (var.Type == gl.GL_FLOAT_MAT3 ? 3 : 4); int bytes = size * size * 4; Utils.assert(dataLen % bytes == 0); int count = dataLen / bytes; res = Utils.makeMatrixString(stream, count, size); break; } #endregion default: { Utils.assert(false); break; } } // switch (var.Type) } var.Value = res; } }