最近在看X11 Server的代码,顺手做下笔记。X11 Server的代码很古老了,有的是1993年写的,目前的X Server实现X.org是从最早的一个X Server实现XFree86 4.4 RC2版本(2004年)派生出来的。
X11 Server编译后会生成若干动态链接库形式的驱动程序和一个可执行程序Xorg. Xorg本质上是一个服务器程序,像其它所有服务器程序一样,它的main函数里有一个while循环,以保证在程序启动后,到程序退出前能够为客户端持续提供服务。Xorg的另一个特点是极具扩展性,所有动态链接库形式的DDX(Device Dependent X)驱动都是以Xorg Module的方式动态加载的,具体加载哪个DDX Driver由Xorg的Config文件配置。
同一个使用glfw的OpenGL程序在Kylin V10系统上可以修改alpha通道改变窗口背景的透明度,而在Ubuntu Focal Fossa系统上却不能?
Alpha通道控制窗口的透明度(transparency)。而X11窗口系统上,alpha通道是否可用,和X11 Server的RENDER扩展有关,下面来自glfw的代码是自明的(self-explanatory)
1 2 3 4 5 6 7 8
| GLFWbool _glfwIsVisualTransparentX11(Visual* visual) { if (!_glfw.x11.xrender.available) return GLFW_FALSE;
XRenderPictFormat* pf = XRenderFindVisualFormat(_glfw.x11.display, visual); return pf && pf->direct.alphaMask; }
|
关于系统上的 X11 Server 的 RENDER 扩展的信息可以通过 xdpyinfo
命令查看(此命令输出很多信息)
xdpyinfo -ext RENDER | awk '/Render formats/,/Screen formats/'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
| Render formats : pict format: format id: 0x25 type: Direct depth: 1 alpha: 0 mask 0x1 red: 0 mask 0x0 green: 0 mask 0x0 blue: 0 mask 0x0 pict format: format id: 0x26 type: Direct depth: 8 alpha: 0 mask 0xff red: 0 mask 0x0 green: 0 mask 0x0 blue: 0 mask 0x0 pict format: format id: 0x27 type: Direct depth: 4 alpha: 0 mask 0xf red: 0 mask 0x0 green: 0 mask 0x0 blue: 0 mask 0x0 pict format: format id: 0x28 type: Direct depth: 32 alpha: 24 mask 0xff red: 16 mask 0xff green: 8 mask 0xff blue: 0 mask 0xff pict format: format id: 0x29 type: Direct depth: 32 alpha: 0 mask 0x0 red: 16 mask 0xff green: 8 mask 0xff blue: 0 mask 0xff pict format: format id: 0x2a type: Direct depth: 32 alpha: 0 mask 0xff red: 8 mask 0xff green: 16 mask 0xff blue: 24 mask 0xff pict format: format id: 0x2b type: Direct depth: 32 alpha: 0 mask 0x0 red: 8 mask 0xff green: 16 mask 0xff blue: 24 mask 0xff pict format: format id: 0x2c type: Direct depth: 24 alpha: 0 mask 0x0 red: 16 mask 0xff green: 8 mask 0xff blue: 0 mask 0xff pict format: format id: 0x2d type: Direct depth: 24 alpha: 0 mask 0x0 red: 0 mask 0xff green: 8 mask 0xff blue: 16 mask 0xff pict format: format id: 0x2e type: Direct depth: 15 alpha: 0 mask 0x0 red: 8 mask 0xf green: 4 mask 0xf blue: 0 mask 0xf pict format: format id: 0x2f type: Direct depth: 15 alpha: 0 mask 0x0 red: 0 mask 0xf green: 4 mask 0xf blue: 8 mask 0xf pict format: format id: 0x30 type: Direct depth: 15 alpha: 0 mask 0x0 red: 10 mask 0x1f green: 5 mask 0x1f blue: 0 mask 0x1f pict format: format id: 0x31 type: Direct depth: 15 alpha: 0 mask 0x0 red: 0 mask 0x1f green: 5 mask 0x1f blue: 10 mask 0x1f pict format: format id: 0x32 type: Direct depth: 16 alpha: 0 mask 0x0 red: 8 mask 0xf green: 4 mask 0xf blue: 0 mask 0xf pict format: format id: 0x33 type: Direct depth: 16 alpha: 0 mask 0x0 red: 0 mask 0xf green: 4 mask 0xf blue: 8 mask 0xf pict format: format id: 0x34 type: Direct depth: 16 alpha: 0 mask 0x0 red: 10 mask 0x1f green: 5 mask 0x1f blue: 0 mask 0x1f pict format: format id: 0x35 type: Direct depth: 16 alpha: 0 mask 0x0 red: 0 mask 0x1f green: 5 mask 0x1f blue: 10 mask 0x1f pict format: format id: 0x36 type: Direct depth: 16 alpha: 15 mask 0x1 red: 10 mask 0x1f green: 5 mask 0x1f blue: 0 mask 0x1f pict format: format id: 0x37 type: Direct depth: 16 alpha: 15 mask 0x1 red: 0 mask 0x1f green: 5 mask 0x1f blue: 10 mask 0x1f pict format: format id: 0x38 type: Direct depth: 16 alpha: 0 mask 0x0 red: 11 mask 0x1f green: 5 mask 0x3f blue: 0 mask 0x1f pict format: format id: 0x39 type: Direct depth: 16 alpha: 0 mask 0x0 red: 0 mask 0x1f green: 5 mask 0x3f blue: 11 mask 0x1f pict format: format id: 0x3a type: Direct depth: 16 alpha: 12 mask 0xf red: 8 mask 0xf green: 4 mask 0xf blue: 0 mask 0xf pict format: format id: 0x3b type: Direct depth: 16 alpha: 12 mask 0xf red: 0 mask 0xf green: 4 mask 0xf blue: 8 mask 0xf pict format: format id: 0x3c type: Direct depth: 32 alpha: 0 mask 0x0 red: 0 mask 0xff green: 8 mask 0xff blue: 16 mask 0xff pict format: format id: 0x3d type: Direct depth: 32 alpha: 30 mask 0x3 red: 20 mask 0x3ff green: 10 mask 0x3ff blue: 0 mask 0x3ff pict format: format id: 0x3e type: Direct depth: 32 alpha: 0 mask 0x0 red: 20 mask 0x3ff green: 10 mask 0x3ff blue: 0 mask 0x3ff pict format: format id: 0x3f type: Direct depth: 32 alpha: 30 mask 0x3 red: 0 mask 0x3ff green: 10 mask 0x3ff blue: 20 mask 0x3ff pict format: format id: 0x40 type: Direct depth: 32 alpha: 0 mask 0x0 red: 0 mask 0x3ff green: 10 mask 0x3ff blue: 20 mask 0x3ff Screen formats :
|
xdpyinfo -ext RENDER | awk '/Screen formats/,/depth formats/'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
| Screen formats : Screen 0 (sub-pixel order Unknown) filters: nearest, bilinear, convolution, fast(nearest), good(bilinear), best(bilinear) visual format: visual id: 0x23 pict format id: 0x2c visual format: visual id: 0x24 pict format id: 0x2c visual format: visual id: 0x296 pict format id: 0x2c visual format: visual id: 0x297 pict format id: 0x2c visual format: visual id: 0x298 pict format id: 0x2c visual format: visual id: 0x299 pict format id: 0x2c visual format: visual id: 0x29a pict format id: 0x2c visual format: visual id: 0x29b pict format id: 0x2c visual format: visual id: 0x29c pict format id: 0x2c visual format: visual id: 0x29d pict format id: 0x2c visual format: visual id: 0x29e pict format id: 0x2c visual format: visual id: 0x29f pict format id: 0x2c visual format: visual id: 0x2a0 pict format id: 0x2c visual format: visual id: 0x2a1 pict format id: 0x2c visual format: visual id: 0x2a2 pict format id: 0x2c visual format: visual id: 0x2a3 pict format id: 0x2c visual format: visual id: 0x2a4 pict format id: 0x2c visual format: visual id: 0x2a5 pict format id: 0x2c visual format: visual id: 0x2a6 pict format id: 0x2c visual format: visual id: 0x2a7 pict format id: 0x2c visual format: visual id: 0x2a8 pict format id: 0x2c visual format: visual id: 0x2a9 pict format id: 0x2c visual format: visual id: 0x2aa pict format id: 0x2c visual format: visual id: 0x2ab pict format id: 0x2c visual format: visual id: 0x2ac pict format id: 0x2c visual format: visual id: 0x2ad pict format id: 0x2c visual format: visual id: 0x2ae pict format id: 0x2c visual format: visual id: 0x2af pict format id: 0x2c visual format: visual id: 0x2b0 pict format id: 0x2c visual format: visual id: 0x2b1 pict format id: 0x2c visual format: visual id: 0x2b2 pict format id: 0x2c visual format: visual id: 0x2b3 pict format id: 0x2c visual format: visual id: 0x2b4 pict format id: 0x2c visual format: visual id: 0x2b5 pict format id: 0x2c visual format: visual id: 0x2b6 pict format id: 0x2c visual format: visual id: 0x2b7 pict format id: 0x2c visual format: visual id: 0x2b8 pict format id: 0x2c visual format: visual id: 0x2b9 pict format id: 0x2c visual format: visual id: 0x2ba pict format id: 0x2c visual format: visual id: 0x2bb pict format id: 0x2c visual format: visual id: 0x2bc pict format id: 0x2c visual format: visual id: 0x2bd pict format id: 0x2c visual format: visual id: 0x2be pict format id: 0x2c visual format: visual id: 0x2bf pict format id: 0x2c visual format: visual id: 0x2c0 pict format id: 0x2c visual format: visual id: 0x2c1 pict format id: 0x2c visual format: visual id: 0x2c2 pict format id: 0x2c visual format: visual id: 0x2c3 pict format id: 0x2c visual format: visual id: 0x2c4 pict format id: 0x2c visual format: visual id: 0x2c5 pict format id: 0x2c visual format: visual id: 0x2c6 pict format id: 0x2c visual format: visual id: 0x2c7 pict format id: 0x2c visual format: visual id: 0x2c8 pict format id: 0x2c visual format: visual id: 0x2c9 pict format id: 0x2c visual format: visual id: 0x2ca pict format id: 0x2c visual format: visual id: 0x2cb pict format id: 0x2c visual format: visual id: 0x2cc pict format id: 0x2c visual format: visual id: 0x2cd pict format id: 0x2c visual format: visual id: 0x2ce pict format id: 0x2c visual format: visual id: 0x2cf pict format id: 0x2c visual format: visual id: 0x2d0 pict format id: 0x2c visual format: visual id: 0x2d1 pict format id: 0x2c visual format: visual id: 0x2d2 pict format id: 0x2c visual format: visual id: 0x2d3 pict format id: 0x2c visual format: visual id: 0x2d4 pict format id: 0x2c visual format: visual id: 0x2d5 pict format id: 0x2c visual format: visual id: 0x2d6 pict format id: 0x2c visual format: visual id: 0x2d7 pict format id: 0x2c visual format: visual id: 0x2d8 pict format id: 0x2c visual format: visual id: 0x2d9 pict format id: 0x2c visual format: visual id: 0x2da pict format id: 0x2c visual format: visual id: 0x2db pict format id: 0x2c visual format: visual id: 0x2dc pict format id: 0x2c visual format: visual id: 0x2dd pict format id: 0x2c visual format: visual id: 0x2de pict format id: 0x2c visual format: visual id: 0x2df pict format id: 0x2c visual format: visual id: 0x2e0 pict format id: 0x2c visual format: visual id: 0x2e1 pict format id: 0x2c visual format: visual id: 0x2e2 pict format id: 0x2c visual format: visual id: 0x2e3 pict format id: 0x2c visual format: visual id: 0x2e4 pict format id: 0x2c visual format: visual id: 0x2e5 pict format id: 0x2c visual format: visual id: 0x2e6 pict format id: 0x2c visual format: visual id: 0x2e7 pict format id: 0x2c visual format: visual id: 0x2e8 pict format id: 0x2c visual format: visual id: 0x2e9 pict format id: 0x2c visual format: visual id: 0x2ea pict format id: 0x2c visual format: visual id: 0x2eb pict format id: 0x2c visual format: visual id: 0x2ec pict format id: 0x2c visual format: visual id: 0x2ed pict format id: 0x2c visual format: visual id: 0x2ee pict format id: 0x2c visual format: visual id: 0x2ef pict format id: 0x2c visual format: visual id: 0x2f0 pict format id: 0x2c visual format: visual id: 0x2f1 pict format id: 0x2c visual format: visual id: 0x2f2 pict format id: 0x2c visual format: visual id: 0x2f3 pict format id: 0x2c visual format: visual id: 0x2f4 pict format id: 0x2c visual format: visual id: 0x2f5 pict format id: 0x2c visual format: visual id: 0x2f6 pict format id: 0x2c visual format: visual id: 0x2f7 pict format id: 0x2c visual format: visual id: 0x2f8 pict format id: 0x2c visual format: visual id: 0x2f9 pict format id: 0x2c visual format: visual id: 0x2fa pict format id: 0x2c visual format: visual id: 0x2fb pict format id: 0x2c visual format: visual id: 0x2fc pict format id: 0x2c visual format: visual id: 0x2fd pict format id: 0x2c visual format: visual id: 0x2fe pict format id: 0x2c visual format: visual id: 0x2ff pict format id: 0x2c visual format: visual id: 0x300 pict format id: 0x2c visual format: visual id: 0x301 pict format id: 0x2c visual format: visual id: 0x302 pict format id: 0x2c visual format: visual id: 0x303 pict format id: 0x2c visual format: visual id: 0x304 pict format id: 0x2c visual format: visual id: 0x305 pict format id: 0x2c visual format: visual id: 0x306 pict format id: 0x2c visual format: visual id: 0x307 pict format id: 0x2c visual format: visual id: 0x308 pict format id: 0x2c visual format: visual id: 0x309 pict format id: 0x2c visual format: visual id: 0x30a pict format id: 0x2c visual format: visual id: 0x30b pict format id: 0x2c visual format: visual id: 0x30c pict format id: 0x2c visual format: visual id: 0x30d pict format id: 0x2c visual format: visual id: 0x30e pict format id: 0x2c visual format: visual id: 0x30f pict format id: 0x2c visual format: visual id: 0x310 pict format id: 0x2c visual format: visual id: 0x311 pict format id: 0x2c visual format: visual id: 0x312 pict format id: 0x2c visual format: visual id: 0x313 pict format id: 0x2c visual format: visual id: 0x314 pict format id: 0x2c visual format: visual id: 0x315 pict format id: 0x2c visual format: visual id: 0x316 pict format id: 0x2c visual format: visual id: 0x317 pict format id: 0x2c visual format: visual id: 0x318 pict format id: 0x2c visual format: visual id: 0x319 pict format id: 0x2c visual format: visual id: 0x31a pict format id: 0x2c visual format: visual id: 0x31b pict format id: 0x2c visual format: visual id: 0x31c pict format id: 0x2c visual format: visual id: 0x31d pict format id: 0x2c visual format: visual id: 0x31e pict format id: 0x2c visual format: visual id: 0x31f pict format id: 0x2c visual format: visual id: 0x320 pict format id: 0x2c visual format: visual id: 0x321 pict format id: 0x2c visual format: visual id: 0x322 pict format id: 0x2c visual format: visual id: 0x323 pict format id: 0x2c visual format: visual id: 0x324 pict format id: 0x2c visual format: visual id: 0x325 pict format id: 0x2c visual format: visual id: 0x326 pict format id: 0x2c visual format: visual id: 0x327 pict format id: 0x2c visual format: visual id: 0x328 pict format id: 0x2c visual format: visual id: 0x329 pict format id: 0x2c visual format: visual id: 0x32a pict format id: 0x2c visual format: visual id: 0x32b pict format id: 0x2c visual format: visual id: 0x32c pict format id: 0x2c visual format: visual id: 0x32d pict format id: 0x2c visual format: visual id: 0x32e pict format id: 0x2c visual format: visual id: 0x32f pict format id: 0x2c visual format: visual id: 0x330 pict format id: 0x2c visual format: visual id: 0x331 pict format id: 0x2c visual format: visual id: 0x332 pict format id: 0x2c visual format: visual id: 0x333 pict format id: 0x2c visual format: visual id: 0x334 pict format id: 0x2c visual format: visual id: 0x335 pict format id: 0x2c visual format: visual id: 0x336 pict format id: 0x2c visual format: visual id: 0x337 pict format id: 0x2c visual format: visual id: 0x338 pict format id: 0x2c visual format: visual id: 0x339 pict format id: 0x2c visual format: visual id: 0x33a pict format id: 0x2c visual format: visual id: 0x33b pict format id: 0x2c visual format: visual id: 0x33c pict format id: 0x2c visual format: visual id: 0x33d pict format id: 0x2c visual format: visual id: 0x33e pict format id: 0x2c visual format: visual id: 0x33f pict format id: 0x2c visual format: visual id: 0x340 pict format id: 0x2c visual format: visual id: 0x341 pict format id: 0x2c visual format: visual id: 0x342 pict format id: 0x2c visual format: visual id: 0x343 pict format id: 0x2c visual format: visual id: 0x344 pict format id: 0x2c visual format: visual id: 0x345 pict format id: 0x2c visual format: visual id: 0x346 pict format id: 0x2c visual format: visual id: 0x347 pict format id: 0x2c visual format: visual id: 0x348 pict format id: 0x2c visual format: visual id: 0x349 pict format id: 0x2c visual format: visual id: 0x34a pict format id: 0x2c visual format: visual id: 0x34b pict format id: 0x2c visual format: visual id: 0x34c pict format id: 0x2c visual format: visual id: 0x34d pict format id: 0x2c visual format: visual id: 0x34e pict format id: 0x2c visual format: visual id: 0x34f pict format id: 0x2c visual format: visual id: 0x350 pict format id: 0x2c visual format: visual id: 0x351 pict format id: 0x2c visual format: visual id: 0x352 pict format id: 0x2c visual format: visual id: 0x353 pict format id: 0x2c visual format: visual id: 0x354 pict format id: 0x2c visual format: visual id: 0x355 pict format id: 0x2c visual format: visual id: 0x356 pict format id: 0x2c visual format: visual id: 0x357 pict format id: 0x2c visual format: visual id: 0x358 pict format id: 0x2c visual format: visual id: 0x359 pict format id: 0x2c visual format: visual id: 0x35a pict format id: 0x2c visual format: visual id: 0x35b pict format id: 0x2c visual format: visual id: 0x35c pict format id: 0x2c visual format: visual id: 0x35d pict format id: 0x2c visual format: visual id: 0x35e pict format id: 0x2c visual format: visual id: 0x35f pict format id: 0x2c visual format: visual id: 0x360 pict format id: 0x2c visual format: visual id: 0x361 pict format id: 0x2c visual format: visual id: 0x362 pict format id: 0x2c visual format: visual id: 0x363 pict format id: 0x2c visual format: visual id: 0x364 pict format id: 0x2c visual format: visual id: 0x365 pict format id: 0x2c visual format: visual id: 0x366 pict format id: 0x2c visual format: visual id: 0x367 pict format id: 0x2c visual format: visual id: 0x368 pict format id: 0x2c visual format: visual id: 0x369 pict format id: 0x2c visual format: visual id: 0x36a pict format id: 0x2c visual format: visual id: 0x36b pict format id: 0x2c visual format: visual id: 0x36c pict format id: 0x2c visual format: visual id: 0x36d pict format id: 0x2c visual format: visual id: 0x36e pict format id: 0x2c visual format: visual id: 0x36f pict format id: 0x2c visual format: visual id: 0x370 pict format id: 0x2c visual format: visual id: 0x371 pict format id: 0x2c visual format: visual id: 0x372 pict format id: 0x2c visual format: visual id: 0x373 pict format id: 0x2c visual format: visual id: 0x374 pict format id: 0x2c visual format: visual id: 0x375 pict format id: 0x2c visual format: visual id: 0x376 pict format id: 0x2c visual format: visual id: 0x377 pict format id: 0x2c visual format: visual id: 0x378 pict format id: 0x2c visual format: visual id: 0x379 pict format id: 0x2c visual format: visual id: 0x37a pict format id: 0x2c visual format: visual id: 0x37b pict format id: 0x2c visual format: visual id: 0x37c pict format id: 0x2c visual format: visual id: 0x37d pict format id: 0x2c visual format: visual id: 0x37e pict format id: 0x2c visual format: visual id: 0x37f pict format id: 0x2c visual format: visual id: 0x380 pict format id: 0x2c visual format: visual id: 0x381 pict format id: 0x2c visual format: visual id: 0x382 pict format id: 0x2c visual format: visual id: 0x383 pict format id: 0x2c visual format: visual id: 0x5b pict format id: 0x28 visual format: visual id: 0x384 pict format id: 0x28 visual format: visual id: 0x385 pict format id: 0x28 visual format: visual id: 0x386 pict format id: 0x28 visual format: visual id: 0x387 pict format id: 0x28 visual format: visual id: 0x388 pict format id: 0x28 visual format: visual id: 0x389 pict format id: 0x28 visual format: visual id: 0x38a pict format id: 0x28 visual format: visual id: 0x38b pict format id: 0x28 visual format: visual id: 0x38c pict format id: 0x28 visual format: visual id: 0x38d pict format id: 0x28 visual format: visual id: 0x38e pict format id: 0x28 visual format: visual id: 0x38f pict format id: 0x28 visual format: visual id: 0x390 pict format id: 0x28 visual format: visual id: 0x391 pict format id: 0x28 visual format: visual id: 0x392 pict format id: 0x28 visual format: visual id: 0x393 pict format id: 0x28 visual format: visual id: 0x394 pict format id: 0x28 visual format: visual id: 0x395 pict format id: 0x28 visual format: visual id: 0x396 pict format id: 0x28 visual format: visual id: 0x397 pict format id: 0x28 visual format: visual id: 0x398 pict format id: 0x28 visual format: visual id: 0x399 pict format id: 0x28 visual format: visual id: 0x39a pict format id: 0x28 visual format: visual id: 0x39b pict format id: 0x28 visual format: visual id: 0x39c pict format id: 0x28 visual format: visual id: 0x39d pict format id: 0x28 visual format: visual id: 0x39e pict format id: 0x28 visual format: visual id: 0x39f pict format id: 0x28 visual format: visual id: 0x3a0 pict format id: 0x28 depth formats:
|
上面使用 xdpyinfo
命令得到两张表:
- Render formats 表列出了所有 RENDER 扩展支持的颜色格式的信息,包括它们的位深 (depth), 以及每个 Component 的位深 (mask)
- Screen formats 表实际上列出的是所有 X Visual 与 Render formats 的绑定关系
接下来只需要查看一下程序(或者 GLFW )选取的 X Visual 的 Render format 的 Alpha 分量的位深是否为 0。 0 意味着 GLFW 获取的 GLFW_TRANSPARENT_FRAMEBUFFER
属性是FALSE
, 也就意味着 GLFW 创建的这个窗口中,无法通过修改颜色的 Alpha 分量来改变窗口的透明度, 因为应用的窗口和桌面背景的融合(你是否能透过窗口看到桌面)是 X11 控制的。
我系统上(WSL Ubuntu 20.04)绝大部分VISUAL对应的都是这个ID为0x2c
的pict format, 所以我不能通过修改alpha通道改变窗口背景或内容的透明度,除非我强制让glfw选择其它的VISUAL(对应的pict format不是0x2c
)。
为了确定这个问题的确是VISUAL惹的祸,我想摆脱glfw,在单纯的GLX环境下测试一下,正好mesa/demos这个工程下有一个glxgears_fbconfig,这个demo允许通过GLX_VISUAL_ID
来指定你想要的VISUAL,我分别使用下面两个VISUAL进行测试
-
visual id: 0x5b, pict format id 0x28
1 2 3 4 5 6 7 8
| pict format: format id: 0x28 type: Direct depth: 32 alpha: 24 mask 0xff red: 16 mask 0xff green: 8 mask 0xff blue: 0 mask 0xff
|
-
visual id: 0x23, pict format id 0x2c
注意,为了更清楚地看出不同,我使用glClearBufferfv
将背景设置为半透明
1 2 3 4 5 6 7 8 9 10 11 12
|
@@ -35,0 +36 @@ +#define GL_GLEXT_PROTOTYPES @@ -242,0 +244 @@ draw(void) + static const GLfloat bg[] = {0.0, 0.0, 0.0, 0.5}; + @@ -243,0 +246 @@ draw(void) + + glClearBufferfv(GL_COLOR, 0, bg); + @@ -439,0 +443 @@ make_window( Display *dpy, const char *name, + + GLX_VISUAL_ID, 0x23,)
|
测试结果如下:
从测试结果看,在VisualID=0x23
的情况下,这个VISUAL对应的pict format
没有alpha通道,所以修改bg
的alpha值不会对窗口背景的透明度有任何影响。
glx visual 和 fbconfig 不是一回事
所以 GLX_VISUAL_ID 和 GLX_FBCONFIG_ID 也不是一回事, 虽然它俩都是 XID
, 但 mesa 的实现虽然将 glx visual 和 fbconfig 统一用 glx_config
来表示, 但
1 2 3 4 5
| _GLX_PUBLIC XVisualInfo * glXChooseVisual(Display * dpy, int screen, int *attribList);
_GLX_PUBLIC GLXFBConfig * glXChooseFBConfig(Display * dpy, int screen, const int *attribList, int *nitems)
|
是完全不同的实现,而且 mesa 的 glXChooseVisual()
实际上无法通过指定 GLX_VISUAL_ID 来选择某个特定的 X Visual (这可能是一个 Bug)。