Previous 15994 Revisions Next

r13306 Friday 18th November, 2011 at 22:31:33 UTC by R. Belmont
SDL updates mirrored from MAME, including better GLSL support and netdev for OS X and SDL-Windows targets (nw)
[src/osd/sdl]drawogl.c netdev.c netdev.h netdev_pcap.c* netdev_pcap.h* netdev_tap.c netdev_tap.h sdl.mak sdlmain.c
[src/osd/sdl/shader]glsl_bilinear_idx16_lut.fsh glsl_bilinear_idx16_lut.fsh.c glsl_plain_idx16_lut.fsh glsl_plain_idx16_lut.fsh.c

src/osd/sdl/sdl.mak
r13305r13306
134134ifeq ($(TARGETOS),linux)
135135BASE_TARGETOS = unix
136136SYNC_IMPLEMENTATION = tc
137SDL_NETWORK = on
137SDL_NETWORK = taptun
138138endif
139139
140140ifeq ($(TARGETOS),freebsd)
r13305r13306
175175SYNC_IMPLEMENTATION = ntc
176176SDLMAIN = $(SDLOBJ)/SDLMain_tmpl.o
177177SDLUTILMAIN = $(SDLOBJ)/SDLMain_tmpl.o
178SDL_NETWORK = pcap
178179MAINLDFLAGS = -Xlinker -all_load
179180NO_X11 = 1
180181ifdef BIGENDIAN
r13305r13306
209210SDLMAIN = $(SDLOBJ)/main.o
210211# needed for unidasm
211212LDFLAGS += -Wl,--allow-multiple-definition
213SDL_NETWORK = pcap
212214
213215# do we have GTK ?
214216ifndef GTK_INSTALL_ROOT
r13305r13306
502504#-------------------------------------------------
503505
504506ifdef USE_NETWORK
505ifeq ($(SDL_NETWORK),on)
507ifeq ($(SDL_NETWORK),taptun)
506508OSDOBJS += \
507509   $(SDLOBJ)/netdev.o \
508510   $(SDLOBJ)/netdev_tap.o
509511
510DEFS += -DSDLMAME_NETWORK
512DEFS += -DSDLMAME_NETWORK -DSDLMAME_NET_TAPTUN
511513endif
514
515ifeq ($(SDL_NETWORK),pcap)
516OSDOBJS += \
517   $(SDLOBJ)/netdev.o \
518   $(SDLOBJ)/netdev_pcap.o
519
520DEFS += -DSDLMAME_NETWORK -DSDLMAME_NET_PCAP
521LIBS += -lpcap
512522endif
523endif
513524
514525#-------------------------------------------------
515526# Dependencies
src/osd/sdl/netdev_pcap.c
r0r13306
1#ifdef SDLMAME_WIN32
2#include "../windows/netdev_pcap.c"
3#else
4
5#include <pcap.h>
6#include "emu.h"
7#include "osdnet.h"
8
9class netdev_pcap : public netdev
10{
11public:
12   netdev_pcap(const char *name, class device_network_interface *ifdev, int rate);
13   ~netdev_pcap();
14
15   int send(UINT8 *buf, int len);
16   void set_mac(const char *mac);
17protected:
18   int recv_dev(UINT8 **buf);
19private:
20   pcap_t *m_p;
21};
22
23netdev_pcap::netdev_pcap(const char *name, class device_network_interface *ifdev, int rate)
24   : netdev(ifdev, rate)
25{
26   char errbuf[PCAP_ERRBUF_SIZE];
27   m_p = pcap_open_live(name, 65535, 1, 1, errbuf);
28   if(!m_p)
29   {
30      mame_print_verbose("Unable to open %s: %s\n", name, errbuf);
31      return;
32   }
33   if(pcap_set_datalink(m_p, DLT_EN10MB) == -1)
34   {
35      mame_print_verbose("Unable to set %s to ethernet", name);
36      pcap_close(m_p);
37      m_p = NULL;
38      return;
39   }
40   set_mac(get_mac());
41}
42
43void netdev_pcap::set_mac(const char *mac)
44{
45   char filter[256];
46   struct bpf_program fp;
47   if(!m_p) return;
48   smame_print_verbose(filter, "ether dst %.2X:%.2X:%.2X:%.2X:%.2X:%.2X or ether multicast or ether broadcast", (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5]);
49   pcap_compile(m_p, &fp, filter, 1, 0);
50   pcap_setfilter(m_p, &fp);
51}
52
53int netdev_pcap::send(UINT8 *buf, int len)
54{
55   if(!m_p) return 0;
56   return (!pcap_sendpacket(m_p, buf, len))?len:0;
57}
58
59int netdev_pcap::recv_dev(UINT8 **buf)
60{
61   struct pcap_pkthdr *header;
62   if(!m_p) return 0;
63   return (pcap_next_ex(m_p, &header, (const u_char **)buf) == 1)?header->len:0;
64}
65
66netdev_pcap::~netdev_pcap()
67{
68   if(m_p) pcap_close(m_p);
69}
70
71static CREATE_NETDEV(create_pcap)
72{
73   class netdev_pcap *dev = new netdev_pcap(ifname, ifdev, rate);
74   return dynamic_cast<netdev *>(dev);
75}
76
77void init_pcap()
78{
79   pcap_if_t *devs;
80   char errbuf[PCAP_ERRBUF_SIZE];
81   if(pcap_findalldevs(&devs, errbuf) == -1)
82   {
83      mame_print_verbose("Unable to get network devices: %s\n", errbuf);
84      return;
85   }
86   while(devs->next)
87   {
88      add_netdev(devs->name, create_pcap);
89      devs = devs->next;
90   }
91}
92
93#endif  // SDLMAME_WIN32
src/osd/sdl/netdev_tap.c
r13305r13306
3838
3939   m_fd = -1;
4040   if((m_fd = open("/dev/net/tun", O_RDWR)) == -1) {
41      logerror("tap: open failed %d\n", errno);
41      mame_printf_verbose("tap: open failed %d\n", errno);
4242      return;
4343   }
4444
r13305r13306
4646   ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
4747   sprintf(ifr.ifr_name, "tap-mess-%d-0", getuid());
4848   if(ioctl(m_fd, TUNSETIFF, (void *)&ifr) == -1) {
49      logerror("tap: ioctl failed %d\n", errno);
49      mame_printf_verbose("tap: ioctl failed %d\n", errno);
5050      close(m_fd);
5151      m_fd = -1;
5252      return;
5353   }
54    mame_printf_verbose("netdev_tap: network up!\n");
5455   strncpy(m_ifname, ifr.ifr_name, 10);
5556   fcntl(m_fd, F_SETFL, O_NONBLOCK);
5657
src/osd/sdl/netdev_pcap.h
r0r13306
1#ifndef __NETDEV_PCAP_H__
2#define __NETDEV_PCAP_H__
3
4void init_pcap();
5
6#endif
src/osd/sdl/netdev_tap.h
r13305r13306
1#ifndef __NETDEV_H
2#define __NETDEV_H
1#ifndef __NETDEV_TAP_H__
2#define __NETDEV_TAP_H__
33
44void init_tap();
55
src/osd/sdl/netdev.c
r13305r13306
11#include "emu.h"
22#include "netdev_tap.h"
3#include "netdev_pcap.h"
34
45void sdlnetdev_init(running_machine &machine)
56{
7    #ifdef SDLMAME_NET_TAPTUN
68   init_tap();
9    #endif
10    #ifdef SDLMAME_NET_PCAP
11    init_pcap();
12    #endif
713}
src/osd/sdl/sdlmain.c
r13305r13306
2525
2626// standard includes
2727
28
2829#ifdef SDLMAME_OS2
2930#define INCL_DOS
3031#include <os2.h>
src/osd/sdl/netdev.h
r13305r13306
1#ifndef __NETDEV_H
2#define __NETDEV_H
1#ifndef __NETDEV_H__
2#define __NETDEV_H__
33
44void sdlnetdev_init(running_machine &machine);
55
src/osd/sdl/drawogl.c
r13305r13306
20182018   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
20192019   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
20202020
2021   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
2022   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
2021   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2022   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
20232023
20242024   pfn_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
20252025               GL_TEXTURE_2D, text_name, 0);
r13305r13306
23042304      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
23052305      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
23062306
2307      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
2308      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
2307      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2308      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
23092309
23102310      assert ( texture->lut_texture );
23112311   }
r13305r13306
23692369      }
23702370      else
23712371      {
2372         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
2373         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
2372         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2373         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
23742374      }
23752375   } else {
23762376      UINT32 * dummy = NULL;
r13305r13306
24002400      }
24012401      else
24022402      {
2403         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
2404         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
2403         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2404         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
24052405      }
24062406   }
24072407
r13305r13306
25342534      if( texture->texTarget==GL_TEXTURE_RECTANGLE_ARB )
25352535      {
25362536         // texture rectangles can't wrap
2537         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
2538         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
2537         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2538         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
25392539      } else {
25402540         // set wrapping mode appropriately
25412541         if (texture->flags & PRIMFLAG_TEXWRAP_MASK)
r13305r13306
25452545         }
25462546         else
25472547         {
2548            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
2549            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
2548            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2549            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
25502550         }
25512551      }
25522552   }
src/osd/sdl/shader/glsl_plain_idx16_lut.fsh.c
r13305r13306
2525"   color_map_coord.y = floor(color_map_coord.x/colortable_sz.x);\n"
2626"   color_map_coord.x =   mod(color_map_coord.x,colortable_sz.x);\n"
2727"\n"
28"   gl_FragColor = texture2D(colortable_texture, color_map_coord / (colortable_pow2_sz-1.0));\n"
28"   gl_FragColor = texture2D(colortable_texture, (color_map_coord+vec2(0.5)) / colortable_pow2_sz);\n"
2929"}\n"
3030"\n"
3131"\n"
src/osd/sdl/shader/glsl_bilinear_idx16_lut.fsh
r13305r13306
2525   color_map_coord.y = floor(color_map_coord.x/colortable_sz.x);
2626   color_map_coord.x =   mod(color_map_coord.x,colortable_sz.x);
2727
28   return texture2D(colortable_texture, color_map_coord/(colortable_pow2_sz-1.0));
28   return texture2D(colortable_texture, (color_map_coord+vec2(0.5)) / colortable_pow2_sz);
2929}
3030
3131void main()
src/osd/sdl/shader/glsl_plain_idx16_lut.fsh
r13305r13306
2424   color_map_coord.y = floor(color_map_coord.x/colortable_sz.x);
2525   color_map_coord.x =   mod(color_map_coord.x,colortable_sz.x);
2626
27   gl_FragColor = texture2D(colortable_texture, color_map_coord / (colortable_pow2_sz-1.0));
27   gl_FragColor = texture2D(colortable_texture, (color_map_coord+vec2(0.5)) / colortable_pow2_sz);
2828}
2929
3030
src/osd/sdl/shader/glsl_bilinear_idx16_lut.fsh.c
r13305r13306
2626"   color_map_coord.y = floor(color_map_coord.x/colortable_sz.x);\n"
2727"   color_map_coord.x =   mod(color_map_coord.x,colortable_sz.x);\n"
2828"\n"
29"   return texture2D(colortable_texture, color_map_coord/(colortable_pow2_sz-1.0));\n"
29"   return texture2D(colortable_texture, (color_map_coord+vec2(0.5)) / colortable_pow2_sz);\n"
3030"}\n"
3131"\n"
3232"void main()\n"

Previous 15994 Revisions Next


© 1998-2018 The MESS Team