Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tex_dump.c 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright 2009 VMware, Inc.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "pipe/p_compiler.h"
  25. #include "pipe/p_format.h"
  26. #include "pipe/p_state.h"
  27. #include "util/u_memory.h"
  28. #include "util/u_debug.h"
  29. #include "util/u_format.h"
  30. #include "util/u_network.h"
  31. #include "util/u_tile.h"
  32. #include "rbug/rbug.h"
  33. static void dump(rbug_texture_t tex,
  34. struct rbug_proto_texture_info_reply *info,
  35. struct rbug_proto_texture_read_reply *read,
  36. int mip)
  37. {
  38. enum pipe_format format = info->format;
  39. uint8_t *data = read->data;
  40. unsigned width = info->width[mip];
  41. unsigned height = info->height[mip];
  42. unsigned dst_stride = width * 4 * 4;
  43. unsigned src_stride = read->stride;
  44. float *rgba = MALLOC(dst_stride * height);
  45. int i;
  46. char filename[512];
  47. util_snprintf(filename, 512, "%llu_%s_%u.bmp",
  48. (unsigned long long)tex, pf_name(info->format), mip);
  49. if (util_format_is_compressed(info->format)) {
  50. debug_printf("skipping: %s\n", filename);
  51. return;
  52. }
  53. debug_printf("saving: %s\n", filename);
  54. for (i = 0; i < height; i++) {
  55. pipe_tile_raw_to_rgba(format, data + src_stride * i,
  56. width, 1,
  57. &rgba[width*4*i], dst_stride);
  58. }
  59. debug_dump_float_rgba_bmp(filename, width, height, rgba, width);
  60. FREE(rgba);
  61. }
  62. static void talk()
  63. {
  64. int c = u_socket_connect("localhost", 13370);
  65. struct rbug_connection *con = rbug_from_socket(c);
  66. struct rbug_header *header;
  67. struct rbug_header *header2;
  68. struct rbug_proto_texture_list_reply *list;
  69. struct rbug_proto_texture_info_reply *info;
  70. struct rbug_proto_texture_read_reply *read;
  71. int i, j;
  72. assert(c >= 0);
  73. assert(con);
  74. debug_printf("Connection get!\n");
  75. debug_printf("Sending get textures\n");
  76. rbug_send_texture_list(con, NULL);
  77. debug_printf("Waiting for textures\n");
  78. header = rbug_get_message(con, NULL);
  79. assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY);
  80. list = (struct rbug_proto_texture_list_reply *)header;
  81. debug_printf("Got textures:\n");
  82. for (i = 0; i < list->textures_len; i++) {
  83. rbug_send_texture_info(con, list->textures[i], NULL);
  84. header = rbug_get_message(con, NULL);
  85. assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY);
  86. info = (struct rbug_proto_texture_info_reply *)header;
  87. for (j = 0; j <= info->last_level; j++) {
  88. rbug_send_texture_read(con, list->textures[i],
  89. 0, j, 0,
  90. 0, 0, info->width[j], info->height[j],
  91. NULL);
  92. header2 = rbug_get_message(con, NULL);
  93. assert(header2->opcode == RBUG_OP_TEXTURE_READ_REPLY);
  94. read = (struct rbug_proto_texture_read_reply *)header2;
  95. dump(list->textures[i], info, read, j);
  96. rbug_free_header(header2);
  97. }
  98. rbug_free_header(header);
  99. }
  100. rbug_free_header(&list->header);
  101. rbug_disconnect(con);
  102. }
  103. int main(int argc, char** argv)
  104. {
  105. talk();
  106. return 0;
  107. }