trunk/src/emu/render.c
| r242658 | r242659 | |
| 201 | 201 | return item_layer(layer); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | //************************************************************************** |
| 205 | // render_texinfo |
| 206 | //************************************************************************** |
| 204 | 207 | |
| 208 | render_texinfo &render_texinfo::operator=(const render_texinfo &src) |
| 209 | { |
| 210 | free_palette(); |
| 211 | base = src.base; |
| 212 | rowpixels = src.rowpixels; |
| 213 | width = src.width; |
| 214 | height = src.height; |
| 215 | seqid = src.seqid; |
| 216 | osddata = src.osddata; |
| 217 | m_palette = src.m_palette; |
| 218 | if (m_palette != NULL) |
| 219 | { |
| 220 | m_palette->ref_count++; |
| 221 | } |
| 222 | return *this; |
| 223 | } |
| 205 | 224 | |
| 225 | void render_texinfo::set_palette(const dynamic_array<rgb_t> *source) |
| 226 | { |
| 227 | free_palette(); |
| 228 | if (source != NULL) |
| 229 | { |
| 230 | m_palette = global_alloc(render_palette_copy); |
| 231 | m_palette->palette.copyfrom(*source); |
| 232 | m_palette->ref_count = 1; |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | m_palette = NULL; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | void render_texinfo::free_palette() |
| 241 | { |
| 242 | if (m_palette != NULL) |
| 243 | { |
| 244 | m_palette->ref_count--; |
| 245 | if (m_palette->ref_count == 0) |
| 246 | { |
| 247 | global_free(m_palette); |
| 248 | } |
| 249 | } |
| 250 | m_palette = NULL; |
| 251 | } |
| 252 | |
| 253 | |
| 206 | 254 | //************************************************************************** |
| 207 | 255 | // RENDER PRIMITIVE |
| 208 | 256 | //************************************************************************** |
| r242658 | r242659 | |
| 214 | 262 | |
| 215 | 263 | void render_primitive::reset() |
| 216 | 264 | { |
| 217 | | memset(&type, 0, FPTR(&texcoords + 1) - FPTR(&type)); |
| 265 | // public state |
| 266 | type = INVALID; |
| 267 | bounds.x0 = 0; |
| 268 | bounds.y0 = 0; |
| 269 | bounds.x1 = 0; |
| 270 | bounds.y1 = 0; |
| 271 | color.a = 0; |
| 272 | color.r = 0; |
| 273 | color.g = 0; |
| 274 | color.b = 0; |
| 275 | flags = 0; |
| 276 | width = 0.0f; |
| 277 | // texcoords; FIXME |
| 278 | |
| 279 | // do not clear m_next! |
| 280 | // memset(&type, 0, FPTR(&texcoords + 1) - FPTR(&type)); |
| 281 | |
| 282 | texture.set_palette(NULL); |
| 283 | texture = render_texinfo(); |
| 218 | 284 | } |
| 219 | 285 | |
| 220 | 286 | |
| r242658 | r242659 | |
| 447 | 513 | // get_scaled - get a scaled bitmap (if we can) |
| 448 | 514 | //------------------------------------------------- |
| 449 | 515 | |
| 450 | | bool render_texture::get_scaled(UINT32 dwidth, UINT32 dheight, render_texinfo &texinfo, render_primitive_list &primlist) |
| 516 | void render_texture::get_scaled(UINT32 dwidth, UINT32 dheight, render_texinfo &texinfo, render_primitive_list &primlist) |
| 451 | 517 | { |
| 452 | 518 | // source width/height come from the source bounds |
| 453 | 519 | int swidth = m_sbounds.width(); |
| r242658 | r242659 | |
| 460 | 526 | texinfo.osddata = m_osddata; |
| 461 | 527 | |
| 462 | 528 | // are we scaler-free? if so, just return the source bitmap |
| 463 | | const rgb_t *palbase = (m_format == TEXFORMAT_PALETTE16 || m_format == TEXFORMAT_PALETTEA16) ? m_bitmap->palette()->entry_list_adjusted() : NULL; |
| 464 | 529 | if (m_scaler == NULL || (m_bitmap != NULL && swidth == dwidth && sheight == dheight)) |
| 465 | 530 | { |
| 466 | 531 | // add a reference and set up the source bitmap |
| r242658 | r242659 | |
| 469 | 534 | texinfo.rowpixels = m_bitmap->rowpixels(); |
| 470 | 535 | texinfo.width = swidth; |
| 471 | 536 | texinfo.height = sheight; |
| 472 | | texinfo.palette = palbase; |
| 537 | // will be set later |
| 538 | texinfo.set_palette(NULL); |
| 473 | 539 | texinfo.seqid = ++m_curseq; |
| 474 | | return true; |
| 475 | 540 | } |
| 541 | else |
| 542 | { |
| 543 | // make sure we can recover the original argb32 bitmap |
| 544 | bitmap_argb32 dummy; |
| 545 | bitmap_argb32 &srcbitmap = (m_bitmap != NULL) ? downcast<bitmap_argb32 &>(*m_bitmap) : dummy; |
| 476 | 546 | |
| 477 | | // make sure we can recover the original argb32 bitmap |
| 478 | | bitmap_argb32 dummy; |
| 479 | | bitmap_argb32 &srcbitmap = (m_bitmap != NULL) ? downcast<bitmap_argb32 &>(*m_bitmap) : dummy; |
| 547 | // is it a size we already have? |
| 548 | scaled_texture *scaled = NULL; |
| 549 | int scalenum; |
| 550 | for (scalenum = 0; scalenum < ARRAY_LENGTH(m_scaled); scalenum++) |
| 551 | { |
| 552 | scaled = &m_scaled[scalenum]; |
| 480 | 553 | |
| 481 | | // is it a size we already have? |
| 482 | | scaled_texture *scaled = NULL; |
| 483 | | int scalenum; |
| 484 | | for (scalenum = 0; scalenum < ARRAY_LENGTH(m_scaled); scalenum++) |
| 485 | | { |
| 486 | | scaled = &m_scaled[scalenum]; |
| 554 | // we need a non-NULL bitmap with matching dest size |
| 555 | if (scaled->bitmap != NULL && dwidth == scaled->bitmap->width() && dheight == scaled->bitmap->height()) |
| 556 | break; |
| 557 | } |
| 487 | 558 | |
| 488 | | // we need a non-NULL bitmap with matching dest size |
| 489 | | if (scaled->bitmap != NULL && dwidth == scaled->bitmap->width() && dheight == scaled->bitmap->height()) |
| 490 | | break; |
| 491 | | } |
| 559 | // did we get one? |
| 560 | if (scalenum == ARRAY_LENGTH(m_scaled)) |
| 561 | { |
| 562 | int lowest = -1; |
| 492 | 563 | |
| 493 | | // did we get one? |
| 494 | | if (scalenum == ARRAY_LENGTH(m_scaled)) |
| 495 | | { |
| 496 | | int lowest = -1; |
| 564 | // didn't find one -- take the entry with the lowest seqnum |
| 565 | for (scalenum = 0; scalenum < ARRAY_LENGTH(m_scaled); scalenum++) |
| 566 | if ((lowest == -1 || m_scaled[scalenum].seqid < m_scaled[lowest].seqid) && !primlist.has_reference(m_scaled[scalenum].bitmap)) |
| 567 | lowest = scalenum; |
| 568 | assert_always(lowest != -1, "Too many live texture instances!"); |
| 497 | 569 | |
| 498 | | // didn't find one -- take the entry with the lowest seqnum |
| 499 | | for (scalenum = 0; scalenum < ARRAY_LENGTH(m_scaled); scalenum++) |
| 500 | | if ((lowest == -1 || m_scaled[scalenum].seqid < m_scaled[lowest].seqid) && !primlist.has_reference(m_scaled[scalenum].bitmap)) |
| 501 | | lowest = scalenum; |
| 502 | | assert_always(lowest != -1, "Too many live texture instances!"); |
| 570 | // throw out any existing entries |
| 571 | scaled = &m_scaled[lowest]; |
| 572 | if (scaled->bitmap != NULL) |
| 573 | { |
| 574 | m_manager->invalidate_all(scaled->bitmap); |
| 575 | global_free(scaled->bitmap); |
| 576 | } |
| 503 | 577 | |
| 504 | | // throw out any existing entries |
| 505 | | scaled = &m_scaled[lowest]; |
| 506 | | if (scaled->bitmap != NULL) |
| 507 | | { |
| 508 | | m_manager->invalidate_all(scaled->bitmap); |
| 509 | | global_free(scaled->bitmap); |
| 510 | | } |
| 578 | // allocate a new bitmap |
| 579 | scaled->bitmap = global_alloc(bitmap_argb32(dwidth, dheight)); |
| 580 | scaled->seqid = ++m_curseq; |
| 511 | 581 | |
| 512 | | // allocate a new bitmap |
| 513 | | scaled->bitmap = global_alloc(bitmap_argb32(dwidth, dheight)); |
| 514 | | scaled->seqid = ++m_curseq; |
| 582 | // let the scaler do the work |
| 583 | (*m_scaler)(*scaled->bitmap, srcbitmap, m_sbounds, m_param); |
| 584 | } |
| 515 | 585 | |
| 516 | | // let the scaler do the work |
| 517 | | (*m_scaler)(*scaled->bitmap, srcbitmap, m_sbounds, m_param); |
| 586 | // finally fill out the new info |
| 587 | primlist.add_reference(scaled->bitmap); |
| 588 | texinfo.base = &scaled->bitmap->pix32(0); |
| 589 | texinfo.rowpixels = scaled->bitmap->rowpixels(); |
| 590 | texinfo.width = dwidth; |
| 591 | texinfo.height = dheight; |
| 592 | // will be set later |
| 593 | texinfo.set_palette(NULL); |
| 594 | texinfo.seqid = scaled->seqid; |
| 518 | 595 | } |
| 519 | | |
| 520 | | // finally fill out the new info |
| 521 | | primlist.add_reference(scaled->bitmap); |
| 522 | | texinfo.base = &scaled->bitmap->pix32(0); |
| 523 | | texinfo.rowpixels = scaled->bitmap->rowpixels(); |
| 524 | | texinfo.width = dwidth; |
| 525 | | texinfo.height = dheight; |
| 526 | | texinfo.palette = palbase; |
| 527 | | texinfo.seqid = scaled->seqid; |
| 528 | | return true; |
| 529 | 596 | } |
| 530 | 597 | |
| 531 | 598 | |
| r242658 | r242659 | |
| 534 | 601 | // palette for a texture |
| 535 | 602 | //------------------------------------------------- |
| 536 | 603 | |
| 537 | | const rgb_t *render_texture::get_adjusted_palette(render_container &container) |
| 604 | const dynamic_array<rgb_t> *render_texture::get_adjusted_palette(render_container &container) |
| 538 | 605 | { |
| 539 | 606 | // override the palette with our adjusted palette |
| 540 | 607 | switch (m_format) |
| r242658 | r242659 | |
| 546 | 613 | |
| 547 | 614 | // if no adjustment necessary, return the raw palette |
| 548 | 615 | if (!container.has_brightness_contrast_gamma_changes()) |
| 549 | | return m_bitmap->palette()->entry_list_adjusted(); |
| 616 | return m_bitmap->palette()->entry_list_adjusted_darray(); |
| 550 | 617 | |
| 551 | 618 | // otherwise, return our adjusted palette |
| 552 | 619 | return container.bcg_lookup_table(m_format, m_bitmap->palette()); |
| r242658 | r242659 | |
| 582 | 649 | m_manager(manager), |
| 583 | 650 | m_screen(screen), |
| 584 | 651 | m_overlaybitmap(NULL), |
| 585 | | m_overlaytexture(NULL) |
| 652 | m_overlaytexture(NULL), |
| 653 | m_bcglookup256(0x400) |
| 586 | 654 | { |
| 587 | 655 | // make sure it is empty |
| 588 | 656 | empty(); |
| r242658 | r242659 | |
| 722 | 790 | // given texture mode |
| 723 | 791 | //------------------------------------------------- |
| 724 | 792 | |
| 725 | | const rgb_t *render_container::bcg_lookup_table(int texformat, palette_t *palette) |
| 793 | const dynamic_array<rgb_t> *render_container::bcg_lookup_table(int texformat, palette_t *palette) |
| 726 | 794 | { |
| 727 | 795 | switch (texformat) |
| 728 | 796 | { |
| r242658 | r242659 | |
| 736 | 804 | recompute_lookups(); |
| 737 | 805 | } |
| 738 | 806 | assert (palette == &m_palclient->palette()); |
| 739 | | return m_bcglookup; |
| 807 | return &m_bcglookup; |
| 740 | 808 | |
| 741 | 809 | case TEXFORMAT_RGB32: |
| 742 | 810 | case TEXFORMAT_ARGB32: |
| 743 | 811 | case TEXFORMAT_YUY16: |
| 744 | | return m_bcglookup256; |
| 812 | return &m_bcglookup256; |
| 745 | 813 | |
| 746 | 814 | default: |
| 747 | 815 | return NULL; |
| r242658 | r242659 | |
| 1726 | 1794 | int height = (finalorient & ORIENTATION_SWAP_XY) ? (prim->bounds.x1 - prim->bounds.x0) : (prim->bounds.y1 - prim->bounds.y0); |
| 1727 | 1795 | width = MIN(width, m_maxtexwidth); |
| 1728 | 1796 | height = MIN(height, m_maxtexheight); |
| 1729 | | if (curitem->texture()->get_scaled(width, height, prim->texture, list)) |
| 1730 | | { |
| 1731 | | // set the palette |
| 1732 | | prim->texture.palette = curitem->texture()->get_adjusted_palette(container); |
| 1733 | 1797 | |
| 1734 | | // determine UV coordinates and apply clipping |
| 1735 | | prim->texcoords = oriented_texcoords[finalorient]; |
| 1736 | | clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords); |
| 1798 | curitem->texture()->get_scaled(width, height, prim->texture, list); |
| 1799 | // set the palette |
| 1800 | #if 1 |
| 1801 | const dynamic_array<rgb_t> *adjusted_pal = curitem->texture()->get_adjusted_palette(container); |
| 1802 | prim->texture.set_palette(adjusted_pal); |
| 1803 | #else |
| 1804 | prim->texture.palette = curitem->texture()->get_adjusted_palette(container); |
| 1805 | #endif |
| 1737 | 1806 | |
| 1738 | | // apply the final orientation from the quad flags and then build up the final flags |
| 1739 | | prim->flags = (curitem->flags() & ~(PRIMFLAG_TEXORIENT_MASK | PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) | |
| 1740 | | PRIMFLAG_TEXORIENT(finalorient) | |
| 1741 | | PRIMFLAG_TEXFORMAT(curitem->texture()->format()); |
| 1742 | | if (blendmode != -1) |
| 1743 | | prim->flags |= PRIMFLAG_BLENDMODE(blendmode); |
| 1744 | | else |
| 1745 | | prim->flags |= PRIMFLAG_BLENDMODE(PRIMFLAG_GET_BLENDMODE(curitem->flags())); |
| 1746 | | } |
| 1807 | // determine UV coordinates and apply clipping |
| 1808 | prim->texcoords = oriented_texcoords[finalorient]; |
| 1809 | clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords); |
| 1810 | |
| 1811 | // apply the final orientation from the quad flags and then build up the final flags |
| 1812 | prim->flags = (curitem->flags() & ~(PRIMFLAG_TEXORIENT_MASK | PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) | |
| 1813 | PRIMFLAG_TEXORIENT(finalorient) | |
| 1814 | PRIMFLAG_TEXFORMAT(curitem->texture()->format()); |
| 1815 | if (blendmode != -1) |
| 1816 | prim->flags |= PRIMFLAG_BLENDMODE(blendmode); |
| 1817 | else |
| 1818 | prim->flags |= PRIMFLAG_BLENDMODE(PRIMFLAG_GET_BLENDMODE(curitem->flags())); |
| 1747 | 1819 | } |
| 1748 | 1820 | else |
| 1749 | 1821 | { |
| r242658 | r242659 | |
| 1778 | 1850 | width = render_round_nearest(prim->bounds.x1) - render_round_nearest(prim->bounds.x0); |
| 1779 | 1851 | height = render_round_nearest(prim->bounds.y1) - render_round_nearest(prim->bounds.y0); |
| 1780 | 1852 | |
| 1781 | | bool got_scaled = container.overlay()->get_scaled( |
| 1853 | container.overlay()->get_scaled( |
| 1782 | 1854 | (container_xform.orientation & ORIENTATION_SWAP_XY) ? height : width, |
| 1783 | 1855 | (container_xform.orientation & ORIENTATION_SWAP_XY) ? width : height, prim->texture, list); |
| 1784 | | if (got_scaled) |
| 1785 | | { |
| 1786 | | // determine UV coordinates |
| 1787 | | prim->texcoords = oriented_texcoords[container_xform.orientation]; |
| 1788 | 1856 | |
| 1789 | | // set the flags and add it to the list |
| 1790 | | prim->flags = PRIMFLAG_TEXORIENT(container_xform.orientation) | |
| 1791 | | PRIMFLAG_BLENDMODE(BLENDMODE_RGB_MULTIPLY) | |
| 1792 | | PRIMFLAG_TEXFORMAT(container.overlay()->format()) | |
| 1793 | | PRIMFLAG_TEXSHADE(1); |
| 1794 | | } |
| 1795 | | list.append_or_return(*prim, !got_scaled); |
| 1857 | // determine UV coordinates |
| 1858 | prim->texcoords = oriented_texcoords[container_xform.orientation]; |
| 1859 | |
| 1860 | // set the flags and add it to the list |
| 1861 | prim->flags = PRIMFLAG_TEXORIENT(container_xform.orientation) | |
| 1862 | PRIMFLAG_BLENDMODE(BLENDMODE_RGB_MULTIPLY) | |
| 1863 | PRIMFLAG_TEXFORMAT(container.overlay()->format()) | |
| 1864 | PRIMFLAG_TEXSHADE(1); |
| 1865 | |
| 1866 | list.append_or_return(*prim, false); |
| 1796 | 1867 | } |
| 1797 | 1868 | } |
| 1798 | 1869 | |
| r242658 | r242659 | |
| 1830 | 1901 | height = MIN(height, m_maxtexheight); |
| 1831 | 1902 | |
| 1832 | 1903 | // get the scaled texture and append it |
| 1833 | | bool clipped = true; |
| 1834 | | if (texture->get_scaled(width, height, prim->texture, list)) |
| 1835 | | { |
| 1836 | | // compute the clip rect |
| 1837 | | render_bounds cliprect; |
| 1838 | | cliprect.x0 = render_round_nearest(xform.xoffs); |
| 1839 | | cliprect.y0 = render_round_nearest(xform.yoffs); |
| 1840 | | cliprect.x1 = render_round_nearest(xform.xoffs + xform.xscale); |
| 1841 | | cliprect.y1 = render_round_nearest(xform.yoffs + xform.yscale); |
| 1842 | | sect_render_bounds(&cliprect, &m_bounds); |
| 1843 | 1904 | |
| 1844 | | // determine UV coordinates and apply clipping |
| 1845 | | prim->texcoords = oriented_texcoords[xform.orientation]; |
| 1846 | | clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords); |
| 1847 | | } |
| 1905 | texture->get_scaled(width, height, prim->texture, list); |
| 1848 | 1906 | |
| 1907 | // compute the clip rect |
| 1908 | render_bounds cliprect; |
| 1909 | cliprect.x0 = render_round_nearest(xform.xoffs); |
| 1910 | cliprect.y0 = render_round_nearest(xform.yoffs); |
| 1911 | cliprect.x1 = render_round_nearest(xform.xoffs + xform.xscale); |
| 1912 | cliprect.y1 = render_round_nearest(xform.yoffs + xform.yscale); |
| 1913 | sect_render_bounds(&cliprect, &m_bounds); |
| 1914 | |
| 1915 | // determine UV coordinates and apply clipping |
| 1916 | prim->texcoords = oriented_texcoords[xform.orientation]; |
| 1917 | bool clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords); |
| 1918 | |
| 1849 | 1919 | // add to the list or free if we're clipped out |
| 1850 | 1920 | list.append_or_return(*prim, clipped); |
| 1851 | 1921 | } |
trunk/src/emu/render.h
| r242658 | r242659 | |
| 167 | 167 | // texture scaling callback |
| 168 | 168 | typedef void (*texture_scaler_func)(bitmap_argb32 &dest, bitmap_argb32 &source, const rectangle &sbounds, void *param); |
| 169 | 169 | |
| 170 | | |
| 171 | 170 | // render_bounds - floating point bounding rectangle |
| 172 | 171 | struct render_bounds |
| 173 | 172 | { |
| r242658 | r242659 | |
| 210 | 209 | |
| 211 | 210 | |
| 212 | 211 | // render_texinfo - texture information |
| 213 | | struct render_texinfo |
| 212 | |
| 213 | |
| 214 | struct render_palette_copy |
| 214 | 215 | { |
| 216 | int ref_count; |
| 217 | dynamic_array<rgb_t> palette; |
| 218 | }; |
| 219 | |
| 220 | class render_texinfo |
| 221 | { |
| 222 | private: |
| 223 | render_texinfo(const render_texinfo &src) {} |
| 224 | public: |
| 225 | render_texinfo() |
| 226 | : base(NULL), rowpixels(0), width(0), height(0), |
| 227 | seqid(0), osddata(0), m_palette(NULL) |
| 228 | {} |
| 229 | ~render_texinfo() |
| 230 | { |
| 231 | free_palette(); |
| 232 | } |
| 233 | |
| 234 | render_texinfo &operator=(const render_texinfo &src); |
| 235 | |
| 215 | 236 | void * base; // base of the data |
| 216 | 237 | UINT32 rowpixels; // pixels per row |
| 217 | 238 | UINT32 width; // width of the image |
| 218 | 239 | UINT32 height; // height of the image |
| 219 | | const rgb_t * palette; // palette for PALETTE16 textures, LUTs for RGB15/RGB32 |
| 220 | 240 | UINT32 seqid; // sequence ID |
| 221 | 241 | UINT64 osddata; // aux data to pass to osd |
| 242 | |
| 243 | const rgb_t * palette() const { return ((m_palette == NULL) ? NULL : &m_palette->palette[0]); } |
| 244 | |
| 245 | void set_palette(const dynamic_array<rgb_t> *source); |
| 246 | |
| 247 | private: |
| 248 | void free_palette(); |
| 249 | |
| 250 | render_palette_copy *m_palette; // palette for PALETTE16 textures, LUTs for RGB15/RGB32 |
| 222 | 251 | }; |
| 223 | 252 | |
| 224 | 253 | |
| r242658 | r242659 | |
| 433 | 462 | |
| 434 | 463 | private: |
| 435 | 464 | // internal helpers |
| 436 | | bool get_scaled(UINT32 dwidth, UINT32 dheight, render_texinfo &texinfo, render_primitive_list &primlist); |
| 437 | | const rgb_t *get_adjusted_palette(render_container &container); |
| 465 | void get_scaled(UINT32 dwidth, UINT32 dheight, render_texinfo &texinfo, render_primitive_list &primlist); |
| 466 | const dynamic_array<rgb_t> *get_adjusted_palette(render_container &container); |
| 438 | 467 | |
| 439 | 468 | static const int MAX_TEXTURE_SCALES = 8; |
| 440 | 469 | |
| r242658 | r242659 | |
| 524 | 553 | bool has_brightness_contrast_gamma_changes() const { return (m_user.m_brightness != 1.0f || m_user.m_contrast != 1.0f || m_user.m_gamma != 1.0f); } |
| 525 | 554 | UINT8 apply_brightness_contrast_gamma(UINT8 value); |
| 526 | 555 | float apply_brightness_contrast_gamma_fp(float value); |
| 527 | | const rgb_t *bcg_lookup_table(int texformat, palette_t *palette = NULL); |
| 556 | const dynamic_array<rgb_t> *bcg_lookup_table(int texformat, palette_t *palette = NULL); |
| 528 | 557 | |
| 529 | 558 | private: |
| 530 | 559 | // an item describes a high level primitive that is added to a container |
| r242658 | r242659 | |
| 576 | 605 | render_texture * m_overlaytexture; // overlay texture |
| 577 | 606 | auto_pointer<palette_client> m_palclient; // client to the screen palette |
| 578 | 607 | dynamic_array<rgb_t> m_bcglookup; // full palette lookup with bcg adjustments |
| 579 | | rgb_t m_bcglookup256[0x400]; // lookup table for brightness/contrast/gamma |
| 608 | dynamic_array<rgb_t> m_bcglookup256; // lookup table for brightness/contrast/gamma |
| 580 | 609 | }; |
| 581 | 610 | |
| 582 | 611 | |
trunk/src/emu/rendersw.inc
| r242658 | r242659 | |
| 130 | 130 | |
| 131 | 131 | static inline UINT32 get_texel_palette16(const render_texinfo &texture, INT32 curu, INT32 curv) |
| 132 | 132 | { |
| 133 | const rgb_t *palbase = texture.palette(); |
| 133 | 134 | if (_BilinearFilter) |
| 134 | 135 | { |
| 135 | 136 | INT32 u0 = curu >> 16; |
| r242658 | r242659 | |
| 144 | 145 | const UINT16 *texbase = reinterpret_cast<const UINT16 *>(texture.base); |
| 145 | 146 | texbase += v0 * texture.rowpixels + u0; |
| 146 | 147 | |
| 147 | | UINT32 pix00 = texture.palette[texbase[0]]; |
| 148 | | UINT32 pix01 = texture.palette[texbase[u1]]; |
| 149 | | UINT32 pix10 = texture.palette[texbase[v1]]; |
| 150 | | UINT32 pix11 = texture.palette[texbase[u1 + v1]]; |
| 148 | UINT32 pix00 = palbase[texbase[0]]; |
| 149 | UINT32 pix01 = palbase[texbase[u1]]; |
| 150 | UINT32 pix10 = palbase[texbase[v1]]; |
| 151 | UINT32 pix11 = palbase[texbase[u1 + v1]]; |
| 151 | 152 | return rgb_bilinear_filter(pix00, pix01, pix10, pix11, curu >> 8, curv >> 8); |
| 152 | 153 | } |
| 153 | 154 | else |
| 154 | 155 | { |
| 155 | 156 | const UINT16 *texbase = reinterpret_cast<const UINT16 *>(texture.base) + (curv >> 16) * texture.rowpixels + (curu >> 16); |
| 156 | | return texture.palette[texbase[0]]; |
| 157 | return palbase[texbase[0]]; |
| 157 | 158 | } |
| 158 | 159 | } |
| 159 | 160 | |
| r242658 | r242659 | |
| 165 | 166 | |
| 166 | 167 | static inline UINT32 get_texel_palette16a(const render_texinfo &texture, INT32 curu, INT32 curv) |
| 167 | 168 | { |
| 169 | const rgb_t *palbase = texture.palette(); |
| 168 | 170 | if (_BilinearFilter) |
| 169 | 171 | { |
| 170 | 172 | INT32 u0 = curu >> 16; |
| r242658 | r242659 | |
| 179 | 181 | const UINT16 *texbase = reinterpret_cast<const UINT16 *>(texture.base); |
| 180 | 182 | texbase += v0 * texture.rowpixels + u0; |
| 181 | 183 | |
| 182 | | UINT32 pix00 = texture.palette[texbase[0]]; |
| 183 | | UINT32 pix01 = texture.palette[texbase[u1]]; |
| 184 | | UINT32 pix10 = texture.palette[texbase[v1]]; |
| 185 | | UINT32 pix11 = texture.palette[texbase[u1 + v1]]; |
| 184 | UINT32 pix00 = palbase[texbase[0]]; |
| 185 | UINT32 pix01 = palbase[texbase[u1]]; |
| 186 | UINT32 pix10 = palbase[texbase[v1]]; |
| 187 | UINT32 pix11 = palbase[texbase[u1 + v1]]; |
| 186 | 188 | return rgba_bilinear_filter(pix00, pix01, pix10, pix11, curu >> 8, curv >> 8); |
| 187 | 189 | } |
| 188 | 190 | else |
| 189 | 191 | { |
| 190 | 192 | const UINT16 *texbase = reinterpret_cast<const UINT16 *>(texture.base) + (curv >> 16) * texture.rowpixels + (curu >> 16); |
| 191 | | return texture.palette[texbase[0]]; |
| 193 | return palbase[texbase[0]]; |
| 192 | 194 | } |
| 193 | 195 | } |
| 194 | 196 | |
| r242658 | r242659 | |
| 912 | 914 | |
| 913 | 915 | static void draw_quad_yuy16_none(const render_primitive &prim, _PixelType *dstdata, UINT32 pitch, quad_setup_data &setup) |
| 914 | 916 | { |
| 915 | | const rgb_t *palbase = prim.texture.palette; |
| 917 | const rgb_t *palbase = prim.texture.palette(); |
| 916 | 918 | INT32 dudx = setup.dudx; |
| 917 | 919 | INT32 dvdx = setup.dvdx; |
| 918 | 920 | INT32 endx = setup.endx; |
| r242658 | r242659 | |
| 1082 | 1084 | |
| 1083 | 1085 | static void draw_quad_rgb32(const render_primitive &prim, _PixelType *dstdata, UINT32 pitch, quad_setup_data &setup) |
| 1084 | 1086 | { |
| 1085 | | const rgb_t *palbase = prim.texture.palette; |
| 1087 | const rgb_t *palbase = prim.texture.palette(); |
| 1086 | 1088 | INT32 dudx = setup.dudx; |
| 1087 | 1089 | INT32 dvdx = setup.dvdx; |
| 1088 | 1090 | INT32 endx = setup.endx; |
| r242658 | r242659 | |
| 1252 | 1254 | |
| 1253 | 1255 | static void draw_quad_rgb32_add(const render_primitive &prim, _PixelType *dstdata, UINT32 pitch, quad_setup_data &setup) |
| 1254 | 1256 | { |
| 1255 | | const rgb_t *palbase = prim.texture.palette; |
| 1257 | const rgb_t *palbase = prim.texture.palette(); |
| 1256 | 1258 | INT32 dudx = setup.dudx; |
| 1257 | 1259 | INT32 dvdx = setup.dvdx; |
| 1258 | 1260 | INT32 endx = setup.endx; |
| r242658 | r242659 | |
| 1390 | 1392 | |
| 1391 | 1393 | static void draw_quad_argb32_alpha(const render_primitive &prim, _PixelType *dstdata, UINT32 pitch, quad_setup_data &setup) |
| 1392 | 1394 | { |
| 1393 | | const rgb_t *palbase = prim.texture.palette; |
| 1395 | const rgb_t *palbase = prim.texture.palette(); |
| 1394 | 1396 | INT32 dudx = setup.dudx; |
| 1395 | 1397 | INT32 dvdx = setup.dvdx; |
| 1396 | 1398 | INT32 endx = setup.endx; |
| r242658 | r242659 | |
| 1536 | 1538 | |
| 1537 | 1539 | static void draw_quad_argb32_multiply(const render_primitive &prim, _PixelType *dstdata, UINT32 pitch, quad_setup_data &setup) |
| 1538 | 1540 | { |
| 1539 | | const rgb_t *palbase = prim.texture.palette; |
| 1541 | const rgb_t *palbase = prim.texture.palette(); |
| 1540 | 1542 | INT32 dudx = setup.dudx; |
| 1541 | 1543 | INT32 dvdx = setup.dvdx; |
| 1542 | 1544 | INT32 endx = setup.endx; |
| r242658 | r242659 | |
| 1655 | 1657 | |
| 1656 | 1658 | static void draw_quad_argb32_add(const render_primitive &prim, _PixelType *dstdata, UINT32 pitch, quad_setup_data &setup) |
| 1657 | 1659 | { |
| 1658 | | const rgb_t *palbase = prim.texture.palette; |
| 1660 | const rgb_t *palbase = prim.texture.palette(); |
| 1659 | 1661 | INT32 dudx = setup.dudx; |
| 1660 | 1662 | INT32 dvdx = setup.dvdx; |
| 1661 | 1663 | INT32 endx = setup.endx; |
trunk/src/osd/sdl/blit13.h
| r242658 | r242659 | |
| 53 | 53 | #define OP_RGB32_ARGB32(_src) ((_src) | 0xff000000) |
| 54 | 54 | |
| 55 | 55 | #define OP_RGB32PAL_ARGB32(_src) \ |
| 56 | | (texsource->palette[0x200 + (((_src) >> 16) & 0xff) ] | \ |
| 57 | | texsource->palette[0x100 + (((_src) >> 8) & 0xff) ] | \ |
| 58 | | texsource->palette[((_src) & 0xff) ] | 0xff000000) |
| 56 | (palbase[0x200 + (((_src) >> 16) & 0xff) ] | \ |
| 57 | palbase[0x100 + (((_src) >> 8) & 0xff) ] | \ |
| 58 | palbase[((_src) & 0xff) ] | 0xff000000) |
| 59 | 59 | |
| 60 | | #define OP_PAL16_ARGB32(_src) (0xff000000 | texsource->palette[_src]) |
| 60 | #define OP_PAL16_ARGB32(_src) (0xff000000 | palbase[_src]) |
| 61 | 61 | |
| 62 | | #define OP_PAL16A_ARGB32(_src) (texsource->palette[_src]) |
| 62 | #define OP_PAL16A_ARGB32(_src) (palbase[_src]) |
| 63 | 63 | |
| 64 | 64 | #define OP_RGB15_ARGB32(_src) (0xff000000 | ((_src & 0x7c00) << 9) | ((_src & 0x03e0) << 6) | ((_src & 0x001f) << 3) | \ |
| 65 | 65 | ((((_src & 0x7c00) << 9) | ((_src & 0x03e0) << 6) | ((_src & 0x001f) << 3) >> 5) & 0x070707)) |
| 66 | 66 | |
| 67 | | #define OP_RGB15PAL_ARGB32(_src) (0xff000000 | texsource->palette[0x40 + ((_src >> 10) & 0x1f)] | \ |
| 68 | | texsource->palette[0x20 + ((_src >> 5) & 0x1f)] | texsource->palette[0x00 + ((_src >> 0) & 0x1f)]) |
| 67 | #define OP_RGB15PAL_ARGB32(_src) (0xff000000 | palbase[0x40 + ((_src >> 10) & 0x1f)] | \ |
| 68 | palbase[0x20 + ((_src >> 5) & 0x1f)] | palbase[0x00 + ((_src >> 0) & 0x1f)]) |
| 69 | 69 | |
| 70 | 70 | #define OP_ARGB32_RGB32(_pixel) premult32(_pixel) |
| 71 | 71 | |
| 72 | | #define OP_PAL16A_RGB32(_src) premult32(texsource->palette[_src]) |
| 72 | #define OP_PAL16A_RGB32(_src) premult32(palbase[_src]) |
| 73 | 73 | |
| 74 | | #define OP_PAL16_ARGB1555(_src) ((texsource->palette[_src]&0xf80000) >> 9 | \ |
| 75 | | (texsource->palette[_src]&0x00f800) >> 6 | \ |
| 76 | | (texsource->palette[_src]&0x0000f8) >> 3 | 0x8000) |
| 74 | #define OP_PAL16_ARGB1555(_src) ((palbase[_src]&0xf80000) >> 9 | \ |
| 75 | (palbase[_src]&0x00f800) >> 6 | \ |
| 76 | (palbase[_src]&0x0000f8) >> 3 | 0x8000) |
| 77 | 77 | |
| 78 | 78 | #define OP_RGB15_ARGB1555(_src) ((_src) | 0x8000) |
| 79 | 79 | |
| 80 | | #define OP_RGB15PAL_ARGB1555(_src) ((texsource->palette[(_src) >> 10] & 0xf8) << 7 | \ |
| 81 | | (texsource->palette[((_src) >> 5) & 0x1f] & 0xf8) << 2 | \ |
| 82 | | (texsource->palette[(_src) & 0x1f] & 0xf8) >> 3 | 0x8000) |
| 80 | #define OP_RGB15PAL_ARGB1555(_src) ((palbase[(_src) >> 10] & 0xf8) << 7 | \ |
| 81 | (palbase[((_src) >> 5) & 0x1f] & 0xf8) << 2 | \ |
| 82 | (palbase[(_src) & 0x1f] & 0xf8) >> 3 | 0x8000) |
| 83 | 83 | |
| 84 | 84 | #define OP_YUV16_UYVY(_src) (_src) |
| 85 | 85 | |
| 86 | | #define OP_YUV16PAL_UYVY(_src) ((texsource->palette[((_src) >> 8) & 0xff] << 8) | ((_src) & 0x00ff)) |
| 86 | #define OP_YUV16PAL_UYVY(_src) ((palbase[((_src) >> 8) & 0xff] << 8) | ((_src) & 0x00ff)) |
| 87 | 87 | |
| 88 | | #define OP_YUV16PAL_YVYU(_src) ((texsource->palette[((_src) >> 8) & 0xff] & 0xff) | ((_src & 0xff) << 8)) |
| 88 | #define OP_YUV16PAL_YVYU(_src) ((palbase[((_src) >> 8) & 0xff] & 0xff) | ((_src & 0xff) << 8)) |
| 89 | 89 | |
| 90 | 90 | #define OP_YUV16_YVYU(_src) ((((_src) >> 8) & 0xff) | ((_src & 0xff) << 8)) |
| 91 | 91 | |
| 92 | 92 | #define OP_YUV16_YUY2(_src) ( ((_src) & 0xff00ff00) | \ |
| 93 | 93 | (((_src)>>16)&0xff) | (((_src)<<16)&0xff0000) ) |
| 94 | 94 | |
| 95 | | #define OP_YUV16PAL_YUY2(_src) ( (texsource->palette[((_src)>>8) & 0xff]) | \ |
| 96 | | (texsource->palette[((_src)>>24) & 0xff]<<16) | \ |
| 95 | #define OP_YUV16PAL_YUY2(_src) ( (palbase[((_src)>>8) & 0xff]) | \ |
| 96 | (palbase[((_src)>>24) & 0xff]<<16) | \ |
| 97 | 97 | (((_src)<<8)&0xff00ff00) ) |
| 98 | 98 | |
| 99 | 99 | #define OP_YUV16_ARGB32(_src) \ |
| r242658 | r242659 | |
| 101 | 101 | | ((UINT64)ycc_to_rgb(((_src) >> 24) & 0xff, (_src) & 0xff , ((_src)>>16) & 0xff) << 32) |
| 102 | 102 | |
| 103 | 103 | #define OP_YUV16PAL_ARGB32(_src) \ |
| 104 | | (UINT64)ycc_to_rgb(texsource->palette[((_src) >> 8) & 0xff], (_src) & 0xff , ((_src)>>16) & 0xff) \ |
| 105 | | | ((UINT64)ycc_to_rgb(texsource->palette[((_src) >> 24) & 0xff], (_src) & 0xff , ((_src)>>16) & 0xff) << 32) |
| 104 | (UINT64)ycc_to_rgb(palbase[((_src) >> 8) & 0xff], (_src) & 0xff , ((_src)>>16) & 0xff) \ |
| 105 | | ((UINT64)ycc_to_rgb(palbase[((_src) >> 24) & 0xff], (_src) & 0xff , ((_src)>>16) & 0xff) << 32) |
| 106 | 106 | |
| 107 | 107 | #define OP_YUV16_ARGB32ROT(_src) pixel_ycc_to_rgb(&(_src)) |
| 108 | 108 | |
| 109 | | #define OP_YUV16PAL_ARGB32ROT(_src) pixel_ycc_to_rgb_pal(&(_src), texsource->palette) |
| 109 | #define OP_YUV16PAL_ARGB32ROT(_src) pixel_ycc_to_rgb_pal(&(_src), palbase) |
| 110 | 110 | |
| 111 | 111 | //============================================================ |
| 112 | 112 | // Copy and rotation |
| r242658 | r242659 | |
| 114 | 114 | |
| 115 | 115 | #define TEXCOPY_M( _name, _src_type, _dest_type, _op, _len_div) \ |
| 116 | 116 | INLINE void texcopy_##_name (texture_info *texture, const render_texinfo *texsource) { \ |
| 117 | const rgb_t *palbase = texsource->palette(); \ |
| 117 | 118 | int x, y; \ |
| 118 | 119 | /* loop over Y */ \ |
| 119 | 120 | for (y = 0; y < texsource->height; y++) { \ |
| r242658 | r242659 | |
| 133 | 134 | |
| 134 | 135 | #define TEXROT( _name, _src_type, _dest_type, _op) \ |
| 135 | 136 | INLINE void texcopy_rot_##_name (texture_info *texture, const render_texinfo *texsource) { \ |
| 137 | const rgb_t *palbase = texsource->palette(); \ |
| 136 | 138 | int x, y; \ |
| 137 | 139 | quad_setup_data *setup = &texture->setup; \ |
| 138 | 140 | int dudx = setup->dudx; \ |
trunk/src/osd/sdl/draw13.c
| r242658 | r242659 | |
| 60 | 60 | |
| 61 | 61 | struct quad_setup_data |
| 62 | 62 | { |
| 63 | quad_setup_data() |
| 64 | : dudx(0), dvdx(0), dudy(0), dvdy(0), startu(0), startv(0), |
| 65 | rotwidth(0), rotheight(0) |
| 66 | {} |
| 63 | 67 | INT32 dudx, dvdx, dudy, dvdy; |
| 64 | 68 | INT32 startu, startv; |
| 65 | 69 | INT32 rotwidth, rotheight; |
| r242658 | r242659 | |
| 90 | 94 | /* texture_info holds information about a texture */ |
| 91 | 95 | struct texture_info |
| 92 | 96 | { |
| 97 | texture_info() |
| 98 | : next(NULL), hash(0), flags(0), rawwidth(0), rawheight(0), format(0), |
| 99 | pixels(NULL), pitch(0), pixels_own(0), texture_id(NULL), copyinfo(NULL), |
| 100 | sdl_access(0), sdl_blendmode(SDL_BLENDMODE_NONE), is_rotated(0), last_access(0) |
| 101 | { |
| 102 | } |
| 93 | 103 | texture_info * next; // next texture in the list |
| 94 | 104 | |
| 95 | 105 | HashT hash; // hash value for the texture (must be >= pointer size) |
| r242658 | r242659 | |
| 117 | 127 | /* sdl_info is the information about SDL for the current screen */ |
| 118 | 128 | struct sdl_info |
| 119 | 129 | { |
| 130 | sdl_info() |
| 131 | : blittimer(0), extra_flags(0), sdl_renderer(NULL), texlist(NULL), |
| 132 | texture_max_width(0), texture_max_height(0), last_hofs(0), last_vofs(0), |
| 133 | resize_pending(0), resize_width(0), resize_height(0), |
| 134 | last_blit_time(0), last_blit_pixels(0) |
| 135 | {} |
| 120 | 136 | INT32 blittimer; |
| 121 | 137 | UINT32 extra_flags; |
| 122 | 138 | |
| r242658 | r242659 | |
| 441 | 457 | |
| 442 | 458 | static void add_list(copy_info **head, copy_info *element, Uint32 bm) |
| 443 | 459 | { |
| 444 | | copy_info *newci = (copy_info *) osd_malloc(sizeof(copy_info)); |
| 460 | copy_info *newci = global_alloc(copy_info); |
| 445 | 461 | *newci = *element; |
| 446 | 462 | |
| 447 | 463 | newci->bm_mask = bm; |
| r242658 | r242659 | |
| 515 | 531 | (int) bi->perf); |
| 516 | 532 | freeme = bi; |
| 517 | 533 | bi = bi->next; |
| 518 | | osd_free(freeme); |
| 534 | global_free(freeme); |
| 519 | 535 | } |
| 520 | 536 | } |
| 521 | 537 | |
| r242658 | r242659 | |
| 543 | 559 | static int drawsdl2_window_create(sdl_window_info *window, int width, int height) |
| 544 | 560 | { |
| 545 | 561 | // allocate memory for our structures |
| 546 | | sdl_info *sdl = (sdl_info *) osd_malloc(sizeof(*sdl)); |
| 562 | sdl_info *sdl = global_alloc(sdl_info); |
| 547 | 563 | |
| 548 | 564 | osd_printf_verbose("Enter drawsdl2_window_create\n"); |
| 549 | 565 | |
| 550 | | memset(sdl, 0, sizeof(*sdl)); |
| 551 | | |
| 552 | 566 | window->dxdata = sdl; |
| 553 | 567 | |
| 554 | 568 | sdl->extra_flags = (window->fullscreen() ? |
| r242658 | r242659 | |
| 819 | 833 | |
| 820 | 834 | SDL_DestroyWindow(window->sdl_window); |
| 821 | 835 | |
| 822 | | osd_free(sdl); |
| 836 | global_free(sdl); |
| 823 | 837 | window->dxdata = NULL; |
| 824 | 838 | } |
| 825 | 839 | |
| r242658 | r242659 | |
| 879 | 893 | texture_info *texture; |
| 880 | 894 | |
| 881 | 895 | // allocate a new texture |
| 882 | | texture = (texture_info *) osd_malloc(sizeof(*texture)); |
| 883 | | memset(texture, 0, sizeof(*texture)); |
| 896 | texture = global_alloc(texture_info); |
| 884 | 897 | |
| 885 | 898 | // fill in the core data |
| 886 | 899 | texture->hash = texture_compute_hash(texsource, flags); |
| r242658 | r242659 | |
| 897 | 910 | texture->format = SDL_TEXFORMAT_ARGB32; |
| 898 | 911 | break; |
| 899 | 912 | case TEXFORMAT_RGB32: |
| 900 | | texture->format = texsource->palette ? SDL_TEXFORMAT_RGB32_PALETTED : SDL_TEXFORMAT_RGB32; |
| 913 | texture->format = texsource->palette() ? SDL_TEXFORMAT_RGB32_PALETTED : SDL_TEXFORMAT_RGB32; |
| 901 | 914 | break; |
| 902 | 915 | case TEXFORMAT_PALETTE16: |
| 903 | 916 | texture->format = SDL_TEXFORMAT_PALETTE16; |
| r242658 | r242659 | |
| 906 | 919 | texture->format = SDL_TEXFORMAT_PALETTE16A; |
| 907 | 920 | break; |
| 908 | 921 | case TEXFORMAT_YUY16: |
| 909 | | texture->format = texsource->palette ? SDL_TEXFORMAT_YUY16_PALETTED : SDL_TEXFORMAT_YUY16; |
| 922 | texture->format = texsource->palette() ? SDL_TEXFORMAT_YUY16_PALETTED : SDL_TEXFORMAT_YUY16; |
| 910 | 923 | break; |
| 911 | 924 | |
| 912 | 925 | default: |
| r242658 | r242659 | |
| 940 | 953 | |
| 941 | 954 | if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC)) |
| 942 | 955 | { |
| 943 | | texture->pixels = osd_malloc_array(texture->setup.rotwidth * texture->setup.rotheight * texture->copyinfo->dst_bpp); |
| 956 | texture->pixels = malloc(texture->setup.rotwidth * texture->setup.rotheight * texture->copyinfo->dst_bpp); |
| 944 | 957 | texture->pixels_own=TRUE; |
| 945 | 958 | } |
| 946 | 959 | /* add us to the texture list */ |
| r242658 | r242659 | |
| 1135 | 1148 | SDL_DestroyTexture(texture->texture_id); |
| 1136 | 1149 | if ( texture->pixels_own ) |
| 1137 | 1150 | { |
| 1138 | | osd_free(texture->pixels); |
| 1151 | free(texture->pixels); |
| 1139 | 1152 | texture->pixels=NULL; |
| 1140 | 1153 | texture->pixels_own=FALSE; |
| 1141 | 1154 | } |
| r242658 | r242659 | |
| 1147 | 1160 | sdl->texlist = NULL; |
| 1148 | 1161 | else |
| 1149 | 1162 | p->next = texture->next; |
| 1150 | | osd_free(texture); |
| 1163 | global_free(texture); |
| 1151 | 1164 | } |
| 1152 | 1165 | |
| 1153 | 1166 | static void drawsdl2_destroy_all_textures(sdl_window_info *window) |
trunk/src/osd/sdl/drawogl.c
| r242658 | r242659 | |
| 161 | 161 | /* texture_info holds information about a texture */ |
| 162 | 162 | struct texture_info |
| 163 | 163 | { |
| 164 | texture_info() |
| 165 | : hash(0), flags(0), rawwidth(0), rawheight(0), |
| 166 | rawwidth_create(0), rawheight_create(0), |
| 167 | type(0), format(0), borderpix(0), xprescale(0), yprescale(0), nocopy(0), |
| 168 | texture(0), texTarget(0), texpow2(0), mpass_dest_idx(0), pbo(0), data(NULL), |
| 169 | data_own(0), texCoordBufferName(0) |
| 170 | { |
| 171 | for (int i=0; i<2; i++) |
| 172 | { |
| 173 | mpass_textureunit[i] = 0; |
| 174 | mpass_texture_mamebm[i] = 0; |
| 175 | mpass_fbo_mamebm[i] = 0; |
| 176 | mpass_texture_scrn[i] = 0; |
| 177 | mpass_fbo_scrn[i] = 0; |
| 178 | } |
| 179 | for (int i=0; i<8; i++) |
| 180 | texCoord[i] = 0.0f; |
| 181 | } |
| 182 | |
| 164 | 183 | HashT hash; // hash value for the texture (must be >= pointer size) |
| 165 | 184 | UINT32 flags; // rendering flags |
| 166 | 185 | render_texinfo texinfo; // copy of the texture info |
| r242658 | r242659 | |
| 198 | 217 | /* sdl_info is the information about SDL for the current screen */ |
| 199 | 218 | struct sdl_info |
| 200 | 219 | { |
| 220 | sdl_info() |
| 221 | : blittimer(0), extra_flags(0), |
| 222 | #if (SDLMAME_SDL2) |
| 223 | gl_context_id(0), |
| 224 | #else |
| 225 | sdlsurf(NULL), |
| 226 | #endif |
| 227 | initialized(0), |
| 228 | last_blendmode(0), |
| 229 | texture_max_width(0), |
| 230 | texture_max_height(0), |
| 231 | texpoweroftwo(0), |
| 232 | usevbo(0), usepbo(0), usefbo(0), useglsl(0), glsl(NULL), |
| 233 | glsl_program_num(0), |
| 234 | glsl_program_mb2sc(0), |
| 235 | usetexturerect(0), |
| 236 | init_context(0), |
| 237 | last_hofs(0.0f), |
| 238 | last_vofs(0.0f), |
| 239 | surf_w(0), |
| 240 | surf_h(0) |
| 241 | { |
| 242 | for (int i=0; i < HASH_SIZE + OVERFLOW_SIZE; i++) |
| 243 | texhash[i] = NULL; |
| 244 | for (int i=0; i < 2*GLSL_SHADER_MAX; i++) |
| 245 | glsl_program[i] = 0; |
| 246 | for (int i=0; i < 8; i++) |
| 247 | texVerticex[i] = 0.0f; |
| 248 | } |
| 249 | |
| 201 | 250 | INT32 blittimer; |
| 202 | 251 | UINT32 extra_flags; |
| 203 | 252 | |
| r242658 | r242659 | |
| 487 | 536 | int has_and_allow_texturerect = 0; |
| 488 | 537 | |
| 489 | 538 | // allocate memory for our structures |
| 490 | | sdl = (sdl_info *) osd_malloc(sizeof(*sdl)); |
| 491 | | memset(sdl, 0, sizeof(*sdl)); |
| 539 | sdl = global_alloc(sdl_info); |
| 492 | 540 | |
| 493 | 541 | window->dxdata = sdl; |
| 494 | 542 | |
| r242658 | r242659 | |
| 1612 | 1660 | } |
| 1613 | 1661 | #endif |
| 1614 | 1662 | |
| 1615 | | osd_free(sdl); |
| 1663 | global_free(sdl); |
| 1616 | 1664 | window->dxdata = NULL; |
| 1617 | 1665 | } |
| 1618 | 1666 | |
| r242658 | r242659 | |
| 1654 | 1702 | if ( texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST] && |
| 1655 | 1703 | !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] && |
| 1656 | 1704 | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1657 | | !texture->borderpix && !texsource->palette && |
| 1705 | !texture->borderpix && !texsource->palette() && |
| 1658 | 1706 | texsource->rowpixels <= sdl->texture_max_width ) |
| 1659 | 1707 | { |
| 1660 | 1708 | texture->nocopy = TRUE; |
| r242658 | r242659 | |
| 2068 | 2116 | texture_info *texture; |
| 2069 | 2117 | |
| 2070 | 2118 | // allocate a new texture |
| 2071 | | texture = (texture_info *) malloc(sizeof(*texture)); |
| 2072 | | memset(texture, 0, sizeof(*texture)); |
| 2119 | texture = global_alloc(texture_info); |
| 2073 | 2120 | |
| 2074 | 2121 | // fill in the core data |
| 2075 | 2122 | texture->hash = texture_compute_hash(texsource, flags); |
| r242658 | r242659 | |
| 2107 | 2154 | texture->format = SDL_TEXFORMAT_ARGB32; |
| 2108 | 2155 | break; |
| 2109 | 2156 | case TEXFORMAT_RGB32: |
| 2110 | | if (texsource->palette != NULL) |
| 2157 | if (texsource->palette() != NULL) |
| 2111 | 2158 | texture->format = SDL_TEXFORMAT_RGB32_PALETTED; |
| 2112 | 2159 | else |
| 2113 | 2160 | texture->format = SDL_TEXFORMAT_RGB32; |
| r242658 | r242659 | |
| 2119 | 2166 | texture->format = SDL_TEXFORMAT_PALETTE16A; |
| 2120 | 2167 | break; |
| 2121 | 2168 | case TEXFORMAT_YUY16: |
| 2122 | | if (texsource->palette != NULL) |
| 2169 | if (texsource->palette() != NULL) |
| 2123 | 2170 | texture->format = SDL_TEXFORMAT_YUY16_PALETTED; |
| 2124 | 2171 | else |
| 2125 | 2172 | texture->format = SDL_TEXFORMAT_YUY16; |
| r242658 | r242659 | |
| 2143 | 2190 | { |
| 2144 | 2191 | if ( texture_shader_create(window, texsource, texture, flags) ) |
| 2145 | 2192 | { |
| 2146 | | free(texture); |
| 2193 | global_free(texture); |
| 2147 | 2194 | return NULL; |
| 2148 | 2195 | } |
| 2149 | 2196 | } |
| r242658 | r242659 | |
| 2229 | 2276 | sdl->texhash[i] = texture; |
| 2230 | 2277 | break; |
| 2231 | 2278 | } |
| 2232 | | assert(i < HASH_SIZE + OVERFLOW_SIZE); |
| 2279 | assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ..."); |
| 2233 | 2280 | } |
| 2234 | 2281 | |
| 2235 | 2282 | if(sdl->usevbo) |
| r242658 | r242659 | |
| 2561 | 2608 | switch (PRIMFLAG_GET_TEXFORMAT(flags)) |
| 2562 | 2609 | { |
| 2563 | 2610 | case TEXFORMAT_PALETTE16: |
| 2564 | | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix, texture->xprescale); |
| 2611 | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette(), texture->borderpix, texture->xprescale); |
| 2565 | 2612 | break; |
| 2566 | 2613 | |
| 2567 | 2614 | case TEXFORMAT_PALETTEA16: |
| 2568 | | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix, texture->xprescale); |
| 2615 | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette(), texture->borderpix, texture->xprescale); |
| 2569 | 2616 | break; |
| 2570 | 2617 | |
| 2571 | 2618 | case TEXFORMAT_RGB32: |
| 2572 | | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix, texture->xprescale); |
| 2619 | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette(), texture->borderpix, texture->xprescale); |
| 2573 | 2620 | break; |
| 2574 | 2621 | |
| 2575 | 2622 | case TEXFORMAT_ARGB32: |
| 2576 | | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix, texture->xprescale); |
| 2623 | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette(), texture->borderpix, texture->xprescale); |
| 2577 | 2624 | break; |
| 2578 | 2625 | |
| 2579 | 2626 | case TEXFORMAT_YUY16: |
| 2580 | | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix, texture->xprescale); |
| 2627 | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette(), texture->borderpix, texture->xprescale); |
| 2581 | 2628 | break; |
| 2582 | 2629 | |
| 2583 | 2630 | default: |
| r242658 | r242659 | |
| 2650 | 2697 | texture->texinfo.width == prim->texture.width && |
| 2651 | 2698 | texture->texinfo.height == prim->texture.height && |
| 2652 | 2699 | texture->texinfo.rowpixels == prim->texture.rowpixels && |
| 2653 | | texture->texinfo.palette == prim->texture.palette && |
| 2700 | /* texture->texinfo.palette() == prim->texture.palette() && */ |
| 2654 | 2701 | ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) |
| 2655 | 2702 | return 1; |
| 2656 | 2703 | else |
| r242658 | r242659 | |
| 3041 | 3088 | sdl->texhash[i] = NULL; |
| 3042 | 3089 | if (texture != NULL) |
| 3043 | 3090 | { |
| 3044 | | if(sdl->usevbo) |
| 3045 | | { |
| 3046 | | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| 3047 | | texture->texCoordBufferName=0; |
| 3048 | | } |
| 3091 | if(sdl->usevbo) |
| 3092 | { |
| 3093 | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| 3094 | texture->texCoordBufferName=0; |
| 3095 | } |
| 3049 | 3096 | |
| 3050 | | if(sdl->usepbo && texture->pbo) |
| 3051 | | { |
| 3052 | | pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); |
| 3053 | | texture->pbo=0; |
| 3054 | | } |
| 3097 | if(sdl->usepbo && texture->pbo) |
| 3098 | { |
| 3099 | pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); |
| 3100 | texture->pbo=0; |
| 3101 | } |
| 3055 | 3102 | |
| 3056 | | if( sdl->glsl_program_num > 1 ) |
| 3057 | | { |
| 3058 | | assert(sdl->usefbo); |
| 3059 | | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); |
| 3060 | | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); |
| 3061 | | } |
| 3103 | if( sdl->glsl_program_num > 1 ) |
| 3104 | { |
| 3105 | assert(sdl->usefbo); |
| 3106 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); |
| 3107 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); |
| 3108 | } |
| 3062 | 3109 | |
| 3063 | | if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) |
| 3064 | | { |
| 3065 | | assert(sdl->usefbo); |
| 3066 | | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); |
| 3067 | | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); |
| 3068 | | } |
| 3110 | if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) |
| 3111 | { |
| 3112 | assert(sdl->usefbo); |
| 3113 | pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]); |
| 3114 | glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]); |
| 3115 | } |
| 3069 | 3116 | |
| 3070 | | glDeleteTextures(1, (GLuint *)&texture->texture); |
| 3071 | | if ( texture->data_own ) |
| 3072 | | { |
| 3073 | | free(texture->data); |
| 3074 | | texture->data=NULL; |
| 3075 | | texture->data_own=FALSE; |
| 3117 | glDeleteTextures(1, (GLuint *)&texture->texture); |
| 3118 | if ( texture->data_own ) |
| 3119 | { |
| 3120 | free(texture->data); |
| 3121 | texture->data=NULL; |
| 3122 | texture->data_own=FALSE; |
| 3123 | } |
| 3124 | global_free(texture); |
| 3076 | 3125 | } |
| 3077 | | free(texture); |
| 3078 | | } |
| 3079 | 3126 | i++; |
| 3080 | 3127 | } |
| 3081 | 3128 | if ( sdl->useglsl ) |
trunk/src/osd/windows/drawd3d.c
| r242658 | r242659 | |
| 528 | 528 | texture.rowpixels = m_default_bitmap.rowpixels(); |
| 529 | 529 | texture.width = m_default_bitmap.width(); |
| 530 | 530 | texture.height = m_default_bitmap.height(); |
| 531 | | texture.palette = NULL; |
| 531 | texture.set_palette(NULL); |
| 532 | 532 | texture.seqid = 0; |
| 533 | 533 | |
| 534 | 534 | // now create it |
| r242658 | r242659 | |
| 545 | 545 | texture.rowpixels = m_vector_bitmap.rowpixels(); |
| 546 | 546 | texture.width = m_vector_bitmap.width(); |
| 547 | 547 | texture.height = m_vector_bitmap.height(); |
| 548 | | texture.palette = NULL; |
| 548 | texture.set_palette(NULL); |
| 549 | 549 | texture.seqid = 0; |
| 550 | 550 | |
| 551 | 551 | // now create it |
| r242658 | r242659 | |
| 2580 | 2580 | switch (PRIMFLAG_GET_TEXFORMAT(flags)) |
| 2581 | 2581 | { |
| 2582 | 2582 | case TEXFORMAT_PALETTE16: |
| 2583 | | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2583 | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2584 | 2584 | break; |
| 2585 | 2585 | |
| 2586 | 2586 | case TEXFORMAT_PALETTEA16: |
| 2587 | | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2587 | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2588 | 2588 | break; |
| 2589 | 2589 | |
| 2590 | 2590 | case TEXFORMAT_RGB32: |
| 2591 | | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2591 | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2592 | 2592 | break; |
| 2593 | 2593 | |
| 2594 | 2594 | case TEXFORMAT_ARGB32: |
| 2595 | | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2595 | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2596 | 2596 | break; |
| 2597 | 2597 | |
| 2598 | 2598 | case TEXFORMAT_YUY16: |
| 2599 | 2599 | if (m_texture_manager->get_yuv_format() == D3DFMT_YUY2) |
| 2600 | | copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2600 | copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2601 | 2601 | else if (m_texture_manager->get_yuv_format() == D3DFMT_UYVY) |
| 2602 | | copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2602 | copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2603 | 2603 | else |
| 2604 | | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2604 | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette(), m_xborderpix); |
| 2605 | 2605 | break; |
| 2606 | 2606 | |
| 2607 | 2607 | default: |