Anonymous avatar Anonymous committed 087bac4

Added gl (incomplete) and cdrom tests.

Comments (0)

Files changed (7)

 ---------------
  - Support for 1 bit depth surfaces.
  - Ported tests: checkkeys, graywin, testalpha, testbitmap
+ - Removed unit/ directory; all tests will reside in test/.
+ - Added SDL_GL_GetAttribute
 
 SDL-ctypes 0.03
 ---------------
 import SDL.constants
 import SDL.dll
 
+# enum CDstatus
+(CD_TRAYEMPTY,
+    CD_STOPPED,
+    CD_PLAYING,
+    CD_PAUSED) = range(4)
+CD_ERROR = -1
+# end enum CDstatus
+
 class SDL_CDtrack(Structure):
     _fields_ = [('id', c_ubyte),
                 ('type', c_ubyte),
                 ('hwdata', c_void_p),
                 ('flags', c_uint)]
 
+# enum SDL_GLattr
+(SDL_GL_RED_SIZE,
+    SDL_GL_GREEN_SIZE,
+    SDL_GL_BLUE_SIZE,
+    SDL_GL_ALPHA_SIZE,
+    SDL_GL_BUFFER_SIZE,
+    SDL_GL_DOUBLEBUFFER,
+    SDL_GL_DEPTH_SIZE,
+    SDL_GL_STENCIL_SIZE,
+    SDL_GL_ACCUM_RED_SIZE,
+    SDL_GL_ACCUM_GREEN_SIZE,
+    SDL_GL_ACCUM_BLUE_SIZE,
+    SDL_GL_ACCUM_ALPHA_SIZE,
+    SDL_GL_STEREO,
+    SDL_GL_MULTISAMPLEBUFFERS,
+    SDL_GL_MULTISAMPLESAMPLES,
+    SDL_GL_ACCELERATED_VISUAL,
+    SDL_GL_SWAP_CONTROL) = range(17)
+# end enum SDL_Glattr
+
 # SDL_VideoInit and SDL_VideoQuit not implemented (internal only, according
 # to SDL_video.h).
 
     arg_types=[c_uint, c_int],
     return_type=c_int)
 
-# SDL_GL_GetAttribute not implemented yet
+_SDL_GL_GetAttribute = SDL.dll.private_function('SDL_GL_GetAttribute',
+    arg_types=[c_int, POINTER(c_int)],
+    return_type=c_int)
+
+def SDL_GL_GetAttribute(attr):
+    '''Get an attribute of the OpenGL subsystem from the windowing
+    interface, such as glX.
+    '''
+    val = c_int()
+    _SDL_GL_GetAttribute(attr, byref(val))
+    return val.value
 
 SDL_GL_SwapBuffers = SDL.dll.function('SDL_GL_SwapBuffers',
     '''Swap the OpenGL buffers, if double-buffering is supported.
 byte swapping in array, esp for audio
 
 SDL_syswm.h - platform dependent
+
+testfile
+

test/testcdrom.py

+#!/usr/bin/env python
+
+'''Test the SDL CD-ROM audio functions.
+'''
+
+__docformat__ = 'restructuredtext'
+__version__ = '$Id: $'
+
+import sys
+
+from SDL import *
+
+def PrintStatus(driveindex, cdrom):
+    status = SDL_CDStatus(cdrom)
+    if status == CD_TRAYEMPTY:
+        status_str = 'tray empty'
+    elif status == CD_STOPPED:
+        status_str = 'stopped'
+    elif status == CD_PLAYING:
+        status_str = 'playing'
+    elif status == CD_PAUSED:
+        status_str = 'paused'
+    elif status == CD_ERROR:
+        status_str = 'error state'
+
+    print 'Drive %d status: %s' % (driveindex, status_str)
+    if status >= CD_PLAYING:
+        m, s, f = FRAMES_TO_MSF(cdrom.cur_frame)
+        print 'Currently playing track %d, %d:%2.2d' % \
+            (cdrom.track[cdrom.cur_track].id, m, s)
+
+def ListTracks(cdrom):
+    SDL_CDStatus(cdrom)
+    print 'Drive tracks: %d' % cdrom.numtracks
+    for i in range(cdrom.numtracks):
+        m, s, f = FRAMES_TO_MSF(cdrom.track[i].length)
+        if f > 0:
+            s += 1
+        if cdrom.track[i].type == SDL_AUDIO_TRACK:
+            trtype = 'audio'
+        elif cdrom.track[i].type == SDL_DATA_TRACK:
+            trtype = 'data'
+        else:
+            trtype = 'unknown'
+        print 'Track (index %d) %d: %d:%2.2d / %d [%s track]' % \
+            (i, cdrom.track[i].id, m, s, cdrom.track[i].length, trtype)
+
+def PrintUsage():
+    print >> sys.stderr, '''Usage %s [drive#] [command] [command] ...
+Where 'command' is one of:
+    -status
+    -list
+    -play [first_track] [first_frame] [num_tracks] [num_frames]
+    -pause
+    -resume
+    -stop
+    -eject
+    -sleep <milliseconds>''' % sys.argv[0]
+
+def shift(lst):
+    if len(lst):
+        return None
+    v = lst[0]
+    del lst[0]
+    return v
+
+if __name__ == '__main__':
+    SDL_Init(SDL_INIT_CDROM)
+
+    if SDL_CDNumDrives() == 0:
+        print 'No CD-ROM devices detected'
+        SDL_Quit()
+        sys.exit(0)
+
+    print 'Drives available: %d' % SDL_CDNumDrives()
+    for i in range(SDL_CDNumDrives()):
+        print 'Drive %d:  "%s"' % (i, SDL_CDName(i))
+
+    drive = 0
+    i = 1
+    try:
+        drive = int(sys.argv[1])
+        i += 1
+    except:
+        pass
+    cdrom = SDL_CDOpen(drive)
+
+    while i < len(sys.argv):
+        arg = sys.argv[i]
+        if arg == '-status':
+            PrintStatus(drive, cdrom)  # not sure why this was commented out
+        elif arg == '-list':
+            ListTracks(cdrom)
+        elif arg == '-play':
+            strack = sframe = ntrack = nframe = 0
+            try:
+                strack = int(sys.argv[i + 1])
+                i += 1
+                sframe = int(sys.argv[i + 1])
+                i += 1
+                ntrack = int(sys.argv[i + 1])
+                i += 1
+                nframe = int(sys.argv[i + 1])
+                i += 1
+            except:
+                pass
+            if CD_INDRIVE(SDL_CDStatus(cdrom)):
+                SDL_CDPlayTracks(cdrom, strack, sframe, ntrack, nframe)
+            else:
+                print >> sys.stderr, 'No CD in drive!'
+        elif arg == '-pause':
+            SDL_CDPause(cdrom)
+        elif arg == '-resume':
+            SDL_CDResume(cdrom)
+        elif arg == '-stop':
+            SDL_CDStop(cdrom)
+        elif arg == '-eject':
+            SDL_CDEject(cdrom)
+        elif arg == '-sleep':
+            SDL_Delay(int(sys.argv[i + 1]))
+            print 'Delayed %d milliseconds' % sys.argv[i + 1]
+            i += 1
+        else:
+            PrintUsage()
+            SDL_CDClose(cdrom)
+            SDL_Quit()
+            sys.exit(1)
+    PrintStatus(drive, cdrom)
+    SDL_CDClose(cdrom)
+    SDL_Quit()
+#!/usr/bin/env python
+
+'''
+'''
+
+__docformat__ = 'restructuredtext'
+__version__ = '$Id: $'
+
+import sys
+
+from SDL import *
+from OpenGL.GL import *
+
+global USE_DEPRECATED_OPENGLBLIT 
+USE_DEPRECATED_OPENGLBLIT = False
+global_image = None
+global_texture = 0
+cursor_texture = 0
+
+SHADED_CUBE = True
+
+def HotKey_ToggleFullScreen():
+    screen = SDL_GetVideoSurface()
+    SDL_WM_ToggleFullScreen(screen)
+    if screen.floags & SDL_FULLSCREEN:
+        s = 'fullscreen'
+    else:
+        s = 'windowed'
+    print 'Toggled fullscreen mode - now %s' % s
+
+def HotKey_ToggleGrab():
+    print 'Ctrl-G: toggling input grab!'
+    mode = SDL_WM_GrabInput(SDL_GRAB_QUERY)
+    if mode == SDL_GRAB_ON:
+        print 'Grab was on'
+    else:
+        print 'Grab was off'
+    mode = SDL_WM_GrabInput(not mode)
+    if mode == SDL_GRAB_ON:
+        print 'Grab is now on'
+    else:
+        print 'Grab is now off'
+
+def HotKey_Iconify():
+    print 'Ctrl-Z: iconifying window!'
+    SDL_WM_IconifyWindow()
+
+def HandleEvent(event):
+    if event.type == SDL_ACTIVEEVENT:
+        pass
+    elif event.type == SDL_QUIT:
+        return 1
+    return 0
+
+def RunGLTest(logo, logocursor, slowly, bpp, gamma, noframe, fsaa, sync, accel):
+    w = 640
+    h = 480
+    done = 0
+    color = [(1.0, 1.0, 0.0),
+             (1.0, 0.0, 0.0),
+             (0.0, 0.0, 0.0),
+             (0.0, 1.0, 0.0),
+             (0.0, 1.0, 1.0),
+             (1.0, 1.0, 1.0),
+             (1.0, 0.0, 1.0),
+             (0.0, 0.0, 1.0)]
+    cube = [( 0.5, 0.5, -0.5), 
+            ( 0.5, -0.5, -0.5),
+            (-0.5, -0.5, -0.5),
+            (-0.5, 0.5, -0.5),
+            (-0.5, 0.5, 0.5),
+            ( 0.5, 0.5, 0.5),
+            ( 0.5, -0.5, 0.5),
+            (-0.5, -0.5, 0.5)]
+
+    SDL_Init(SDL_INIT_VIDEO)
+
+    if bpp == 0:
+        if SDL_GetVideoInfo().vfmt.BitsPerPixel <= 8:
+            bpp = 8
+        else:
+            bpp = 16 # More doesn't seem to work.. [TODO: huh?]
+
+    if logo and USE_DEPRECATED_OPENGLBLIT:
+        video_flags = SDL_OPENGLBLIT
+    else:
+        video_flags = SDL_OPENGL
+
+    if '-fullscreen' in sys.argv:
+        video_flags |= SDL_FULLSCREEN
+
+    if noframe:
+        video_flags |= SDL_NOFRAME
+
+    if bpp == 8:
+        rgb_size = (3, 3, 2)
+    elif bpp in (15, 16):
+        rgb_size = (5, 5, 5)
+    else:
+        rgb_size = (8, 8, 8)
+
+    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0])
+    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1])
+    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2])
+    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16)
+    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
+    if fsaa:
+        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)
+        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa)
+    if accel:
+        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1)
+    if sync:
+        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1)
+    else:
+        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0)
+    SDL_SetVideoMode(w, h, bpp, video_flags)
+    
+    print 'Screen BPP: %d' % SDL_GetVideoSurface().format.BitsPerPixel
+    print
+    print 'Vendor       : %s' % glGetString(GL_VENDOR)
+    print 'Renderer     : %s' % glGetString(GL_RENDERER)
+    print 'Version      : %s' % glGetString(GL_VERSION)
+    print 'Extensions   : %s' % glGetString(GL_EXTENSIONS)
+
+    value = SDL_GL_GetAttribute(SDL_GL_RED_SIZE)
+    print 'SDL_GL_RED_SIZE: requested %d, got %d' % (rgb_size[0], value)
+    value = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE)
+    print 'SDL_GL_GREEN_SIZE: requested %d, got %d' % (rgb_size[1], value)
+    value = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE)
+    print 'SDL_GL_BLUE_SIZE: requested %d, got %d' % (rgb_size[2], value)
+    value = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE)
+    print 'SDL_GL_DEPTH_SIZE: requested %d, got %d' % (16, value)
+    value = SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER)
+    print 'SDL_GL_DEPTH_SIZE: requested %d, got %d' % (1, value)
+    if fsaa:
+        value = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS)
+        print 'SDL_GL_MULTISAMPLEBUFFERS: requested %d, got %d' % (1, value)
+        value = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES)
+        print 'SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d' % (fsaa, value)
+    if accel:
+        value = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL)
+        print 'SDL_GL_ACCELERATED_VISUAL: requested %d, got %d' % (1, value)
+    if sync:
+        value = SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL)
+        print 'SDL_GL_SWAP_CONTROL: requested %d, got %d' % (1, value)
+
+    SDL_WM_SetCaption('SDL GL test', 'testgl')
+    if gamma != 0.0:
+        SDL_SetGamma(gamma, gamma, gamma)
+
+    glViewport(0, 0, w, h)
+    glMatrixMode(GL_PROJECTION)
+    glLoadIdentity()
+    
+    glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 )
+
+    glMatrixMode( GL_MODELVIEW )
+    glLoadIdentity( )
+
+    glEnable(GL_DEPTH_TEST)
+
+    glDepthFunc(GL_LESS)
+
+    glShadeModel(GL_SMOOTH)
+
+    # Loop until done
+    start_time = SDL_GetTicks()
+    frames = 0
+    while not done:
+        glClearColor( 0.0, 0.0, 0.0, 1.0 )
+        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+
+        glBegin( GL_QUADS )
+        if SHADED_CUBE:
+            glColor(color[0])
+            glVertex(cube[0])
+            glColor(color[1])
+            glVertex(cube[1])
+            glColor(color[2])
+            glVertex(cube[2])
+            glColor(color[3])
+            glVertex(cube[3])
+            
+            glColor(color[3])
+            glVertex(cube[3])
+            glColor(color[4])
+            glVertex(cube[4])
+            glColor(color[7])
+            glVertex(cube[7])
+            glColor(color[2])
+            glVertex(cube[2])
+            
+            glColor(color[0])
+            glVertex(cube[0])
+            glColor(color[5])
+            glVertex(cube[5])
+            glColor(color[6])
+            glVertex(cube[6])
+            glColor(color[1])
+            glVertex(cube[1])
+            
+            glColor(color[5])
+            glVertex(cube[5])
+            glColor(color[4])
+            glVertex(cube[4])
+            glColor(color[7])
+            glVertex(cube[7])
+            glColor(color[6])
+            glVertex(cube[6])
+
+            glColor(color[5])
+            glVertex(cube[5])
+            glColor(color[0])
+            glVertex(cube[0])
+            glColor(color[3])
+            glVertex(cube[3])
+            glColor(color[4])
+            glVertex(cube[4])
+
+            glColor(color[6])
+            glVertex(cube[6])
+            glColor(color[1])
+            glVertex(cube[1])
+            glColor(color[2])
+            glVertex(cube[2])
+            glColor(color[7])
+            glVertex(cube[7])
+        else: # flat cube
+            glColor(1.0, 0.0, 0.0)
+            glVertex(cube[0])
+            glVertex(cube[1])
+            glVertex(cube[2])
+            glVertex(cube[3])
+            
+            glColor(0.0, 1.0, 0.0)
+            glVertex(cube[3])
+            glVertex(cube[4])
+            glVertex(cube[7])
+            glVertex(cube[2])
+            
+            glColor(0.0, 0.0, 1.0)
+            glVertex(cube[0])
+            glVertex(cube[5])
+            glVertex(cube[6])
+            glVertex(cube[1])
+            
+            glColor(0.0, 1.0, 1.0)
+            glVertex(cube[5])
+            glVertex(cube[4])
+            glVertex(cube[7])
+            glVertex(cube[6])
+
+            glColor(1.0, 1.0, 0.0)
+            glVertex(cube[5])
+            glVertex(cube[0])
+            glVertex(cube[3])
+            glVertex(cube[4])
+
+            glColor(1.0, 0.0, 1.0)
+            glVertex(cube[6])
+            glVertex(cube[1])
+            glVertex(cube[2])
+            glVertex(cube[7])
+
+        glEnd( )
+        
+        glMatrixMode(GL_MODELVIEW)
+        glRotate(5.0, 1.0, 1.0, 1.0)
+
+        # Draw 2D logo onto the 3D display
+        if logo:
+            if USE_DEPRECATED_OPENGLBLIT:
+                pass
+            else:
+                pass # TODO
+
+        if logocursor:
+            pass # TODO
+
+        SDL_GL_SwapBuffers()
+
+        if slowly:
+            SDL_Delay(20)
+
+        event = SDL_PollEventAndReturn()
+        while event:
+            done = HandleEvent(event)
+            event = SDL_PollEventAndReturn()
+        frames += 1
+
+    this_time = SDL_GetTicks()
+    if this_time != start_time:
+        print '%2.2f FPS' % (frames / float(this_time - start_time) * 1000.0)
+
+    if global_image:
+        SDL_FreeSurface(global_image)
+    if global_texture:
+        glDeleteTextures(1, global_texture)
+    if cursor_texture:
+        glDeleteTextures(1, cursor_texture)
+    
+    SDL_Quit()
+
+if __name__ == '__main__':
+    logo = logocursor = 0
+    bpp = 0
+    slowly = 0
+    gamma = 0.0
+    noframe = 0
+    fsaa = 0
+    accel = 0
+    sync = 0
+    numtests = 1
+    i = 1
+    while i < len(sys.argv):
+        arg = sys.argv[i]
+        if arg == '-twice':
+            numtests += 1
+        elif arg == '-logo':
+            logo = 1
+        elif arg == '-logoblit':
+            logo = 1
+            USE_DEPRECATED_OPENGLBLIT = True
+        elif arg == '-logocursor':
+            logocursor = 1
+        elif arg == '-slow':
+            slowly = 1
+        elif arg == '-bpp':
+            i += 1
+            bpp = int(sys.argv[i])
+        elif arg == '-gamma':
+            i += 1
+            gamma = float(sys.argv[i])
+        elif arg == '-noframe':
+            noframe = 1
+        elif arg == '-fsaa':
+            fsaa += 1
+        elif arg == '-accel':
+            accel += 1
+        elif arg == '-sync':
+            sync += 1
+        elif arg[:2] == '-h':
+            print ('Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n]'+\
+                ' [-gamma n] [-noframe] [-fsaa] [-fullscreen]') % sys.argv[0]
+            sys.exit(0)
+        i += 1
+
+    for i in range(numtests):
+        RunGLTest(logo, logocursor, slowly, bpp, gamma, noframe, fsaa, 
+                  sync, accel)

unit/video.py

-#!/usr/bin/env python
-
-'''
-'''
-
-__docformat__ = 'restructuredtext'
-__version__ = '$Id: $'
-
-import sys
-import os.path
-import unittest
-
-from SDL import *
-
-class SDL_Video_TestCase(unittest.TestCase):
-    def setUp(self):
-        SDL_Init(SDL_INIT_VIDEO)
-
-class SDL_Video_MapTest(SDL_Video_TestCase):
-    def testMapRGB(self):
-        info = SDL_GetVideoInfo()
-        pf = info.vfmt
-        for t in [(0, 0, 0),
-                  (255, 0, 0),
-                  (0xde, 0xea, 0xbe)]:
-            opaque = SDL_MapRGB(pf, *t)
-            assert t == SDL_GetRGB(opaque, pf)
-
-    def testMapRGBA(self):
-        # TODO init a surface w/ alpha so can test this properly
-        info = SDL_GetVideoInfo()
-        pf = info.vfmt
-        for t in [(0, 0, 0, 255),
-                  (255, 0, 0, 255),
-                  (255, 255, 255, 255),
-                  (0xde, 0xea, 0xbe, 255)]:
-            opaque = SDL_MapRGBA(pf, *t)
-            assert t == SDL_GetRGBA(opaque, pf)
-
-if __name__ == '__main__':
-    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.