diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 42: Refactor Screen class.

Message ID 20110721123633.17019.94905.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Alexandros Frantzis July 21, 2011, 12:36 p.m. UTC
------------------------------------------------------------
revno: 42
committer: Alexandros Frantzis <alf82@freemail.gr>
timestamp: Mon 2010-07-12 15:15:52 +0300
message:
  Refactor Screen class.
removed:
  src/screen.cpp
added:
  src/screen-sdl-gl.cpp
  src/screen-sdl-gl.h
  src/screen-sdl.cpp
  src/screen-sdl.h
modified:
  src/main.cpp
  src/screen.h


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/main.cpp'
--- src/main.cpp	2010-07-12 10:06:29 +0000
+++ src/main.cpp	2010-07-12 12:15:52 +0000
@@ -1,6 +1,6 @@ 
 #include "oglsdl.h"
 
-#include "screen.h"
+#include "screen-sdl-gl.h"
 #include "scene.h"
 
 int main(int argc, char *argv[])
@@ -8,13 +8,19 @@ 
     SDL_Event event;
     int running = 1;
     unsigned current_scene = 0;
-    Screen screen;
+
+    // Create the screen
+    ScreenSDLGL screen(800, 600, 24, 0);
+
+    if (!screen.mInitSuccess) {
+        printf("Error: %s: Could not initialize screen\n", __FUNCTION__);
+        return 1;
+    }
 
     printf("===================================================\n");
     printf("    GLMark 08\n");
     printf("===================================================\n");
-    if(!screen.init())
-        return 0;
+    screen.print_info();
     printf("===================================================\n");
 
     // Create the scenes.

=== added file 'src/screen-sdl-gl.cpp'
--- src/screen-sdl-gl.cpp	1970-01-01 00:00:00 +0000
+++ src/screen-sdl-gl.cpp	2010-07-12 12:15:52 +0000
@@ -0,0 +1,40 @@ 
+#include "screen-sdl-gl.h"
+
+ScreenSDLGL::ScreenSDLGL(int pWidth, int pHeight, int pBpp, int pFullScreen, int pFlags)
+    : ScreenSDL(pWidth, pHeight, pBpp, pFullScreen, pFlags | SDL_OPENGL)
+{
+    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
+    glClearDepth(1.0f);
+    glEnable(GL_DEPTH_TEST);
+    glDepthFunc(GL_LEQUAL);
+    glEnable(GL_CULL_FACE);
+    glCullFace(GL_BACK);
+
+    glViewport(0, 0, mWidth, mHeight);
+
+    clear();
+}
+
+ScreenSDLGL::~ScreenSDLGL()
+{
+}
+
+
+void ScreenSDLGL::clear()
+{
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+}
+
+void ScreenSDLGL::update()
+{
+    SDL_GL_SwapBuffers();
+}
+
+void ScreenSDLGL::print_info()
+{
+    printf("    OpenGL Information\n");
+    printf("    GL_VENDOR:     %s\n", glGetString(GL_VENDOR));
+    printf("    GL_RENDERER:   %s\n", glGetString(GL_RENDERER));
+    printf("    GL_VERSION:    %s\n", glGetString(GL_VERSION));
+}
+

=== added file 'src/screen-sdl-gl.h'
--- src/screen-sdl-gl.h	1970-01-01 00:00:00 +0000
+++ src/screen-sdl-gl.h	2010-07-12 12:15:52 +0000
@@ -0,0 +1,17 @@ 
+#ifndef _SCREEN_SDL_GL_H
+#define _SCREEN_SDL_GL_H
+
+#include "screen-sdl.h"
+
+class ScreenSDLGL : public ScreenSDL
+{
+public:
+    ScreenSDLGL(int pWidth, int pHeight, int pBpp, int pFullscreen, int pFlags = 0);
+    ~ScreenSDLGL();
+
+    virtual void clear();
+    virtual void update();
+    virtual void print_info();
+};
+
+#endif

=== added file 'src/screen-sdl.cpp'
--- src/screen-sdl.cpp	1970-01-01 00:00:00 +0000
+++ src/screen-sdl.cpp	2010-07-12 12:15:52 +0000
@@ -0,0 +1,64 @@ 
+#include "screen-sdl.h"
+
+ScreenSDL::ScreenSDL(int pWidth, int pHeight, int pBpp, int pFullScreen, int pFlags)
+{
+    mWidth = pWidth;
+    mHeight = pHeight;
+    mFullScreen = pFullScreen;
+    mBpp = pBpp;
+
+    if (mFullScreen)
+        pFlags |= SDL_FULLSCREEN;
+
+#ifdef _DEBUG
+    printf("Initializing Screen...           ");
+#endif
+    if(SDL_Init(SDL_INIT_VIDEO) < 0)
+    {
+        fprintf(stderr, "[ Fail ] - Video initialization failed: %s\n", SDL_GetError());
+        return;
+    }
+
+    mInfo = SDL_GetVideoInfo();
+
+    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
+    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
+    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
+    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+    if(SDL_SetVideoMode(mWidth, mHeight, mBpp, pFlags) == 0)
+    {
+        fprintf(stderr, "[ Fail ] - Video mode set failed: %s\n", SDL_GetError());
+        return;
+    }
+
+    SDL_WM_SetCaption("GLMark 08", NULL);
+
+    mProjection.perspective(60.0, mWidth / (float)mHeight, 1.0, 1024.0);
+
+#ifdef _DEBUG
+    mProjection.display("Projection");
+#endif
+
+    mInitSuccess = 1;
+}
+
+ScreenSDL::~ScreenSDL()
+{
+    SDL_Quit();
+}
+
+
+void ScreenSDL::clear()
+{
+}
+
+void ScreenSDL::update()
+{
+}
+
+void ScreenSDL::print_info()
+{
+}
+

=== added file 'src/screen-sdl.h'
--- src/screen-sdl.h	1970-01-01 00:00:00 +0000
+++ src/screen-sdl.h	2010-07-12 12:15:52 +0000
@@ -0,0 +1,20 @@ 
+#ifndef _SCREEN_SDL_H
+#define _SCREEN_SDL_H
+
+#include "screen.h"
+
+class ScreenSDL : public Screen
+{
+public:
+    ScreenSDL(int pWidth, int pHeight, int pBpp, int pFullscreen, int pFlags = 0);
+    ~ScreenSDL();
+
+    virtual void clear();
+    virtual void update();
+    virtual void print_info();
+
+protected:
+    const SDL_VideoInfo *mInfo;
+};
+
+#endif

=== removed file 'src/screen.cpp'
--- src/screen.cpp	2010-07-12 10:06:29 +0000
+++ src/screen.cpp	1970-01-01 00:00:00 +0000
@@ -1,98 +0,0 @@ 
-#include "screen.h"
-
-Screen::Screen()
-{
-    mWidth = 800;
-    mHeight = 600;
-    mBpp = 24;
-    mFlags = SDL_OPENGL;
-    mFullScreen = false;
-
-    mInfo = SDL_GetVideoInfo();
-}
-
-Screen::~Screen()
-{
-    SDL_Quit();
-}
-
-Screen::Screen(int pWidth, int pHeight, int pBpp, int pFlags)
-{
-    mWidth = pWidth;
-    mHeight = pHeight;
-    mBpp = pBpp;
-    mFlags = SDL_OPENGL | pFlags;
-
-    mInfo = SDL_GetVideoInfo();
-}
-
-int Screen::init()
-{
-#ifdef _DEBUG
-    printf("Initializing Screen...           ");
-#endif
-    if(SDL_Init(SDL_INIT_VIDEO) < 0)
-    {
-        fprintf(stderr, "[ Fail ] - Video initialization failed: %s\n", SDL_GetError());
-        return 0;
-    }
-
-    if(mFullScreen)
-        mFlags = SDL_OPENGL | SDL_FULLSCREEN;
-
-    mInfo = SDL_GetVideoInfo();
-
-    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
-    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
-    if(SDL_SetVideoMode(mWidth, mHeight, mBpp, mFlags) == 0)
-    {
-        fprintf(stderr, "[ Fail ] - Video mode set failed: %s\n", SDL_GetError());
-        return 0;
-    }
-
-    SDL_WM_SetCaption("GLMark 08", NULL);
-
-    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
-    glClearDepth(1.0f);
-    glEnable(GL_DEPTH_TEST);
-    glDepthFunc(GL_LEQUAL);
-    glEnable(GL_CULL_FACE);
-    glCullFace(GL_BACK);
-
-    glViewport(0, 0, mWidth, mHeight);
-
-    clear();
-
-    mProjection.perspective(60.0, mWidth / (float)mHeight, 1.0, 1024.0);
-
-#ifdef _DEBUG
-    mProjection.display("Projection");
-
-    printf("[ Success ]\n");
-#endif
-    print_info();
-    return 1;
-}
-
-void Screen::clear()
-{
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-}
-
-void Screen::update()
-{
-    SDL_GL_SwapBuffers();
-}
-
-void Screen::print_info()
-{
-    printf("    OpenGL Information\n");
-    printf("    GL_VENDOR:     %s\n", glGetString(GL_VENDOR));
-    printf("    GL_RENDERER:   %s\n", glGetString(GL_RENDERER));
-    printf("    GL_VERSION:    %s\n", glGetString(GL_VERSION));
-}
-

=== modified file 'src/screen.h'
--- src/screen.h	2010-07-12 10:06:29 +0000
+++ src/screen.h	2010-07-12 12:15:52 +0000
@@ -9,22 +9,16 @@ 
 class Screen
 {
 public:
-    const SDL_VideoInfo *mInfo;
-    
     int mWidth;
     int mHeight;
     int mBpp;
-    int mFlags;
     int mFullScreen;
     Matrix4f mProjection;
+    int mInitSuccess;
 
-    Screen();
-    ~Screen();
-    Screen(int pWidth, int pHeight, int pBpp, int pFlags);
-    int init();
-    void clear();
-    void update();
-    void print_info();
+    virtual void clear() = 0;
+    virtual void update() = 0;
+    virtual void print_info() = 0;
 };
 
 #endif