CTC++ Coverage Report - Execution Profile   #6/7

Directory Summary | Files Summary | Functions Summary | Untested Code | Execution Profile
To files: First | Previous | Next | Last | Index | No Index


File: F:\ctcwork\demos\cube\cubeview.cpp
Instrumentation mode: multicondition
TER: 63 % (69/109), 79 % (155/196) statement

Hits/True False -Line Source

 // cubeview.cpp : implementation of the CCubeView class
 //
 // This is a part of the Microsoft Foundation Classes C++ library.
 // Copyright (c) Microsoft Corporation.  All rights reserved.
 //
 // This source code is only intended as a supplement to the
 // Microsoft Foundation Classes Reference and related
 // electronic documentation provided with the library.
 // See these sources for detailed information regarding the
 10 // Microsoft Foundation Classes product.
 11 
 12 #include "stdafx.h"
 13 #include "cube.h"
 14 
 15 #include "cubedoc.h"
 16 #include "cubeview.h"
 17 
 18 #include "gl/gl.h"
 19 #include "gl/glu.h"
 20 
 21 #ifdef _DEBUG
 22 #undef THIS_FILE
 23 static char BASED_CODE THIS_FILE[] = __FILE__;
 24 #endif
 25 
 26 unsigned char threeto8[8] =
 27 {
 28    0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
 29 };
 30 
 31 unsigned char twoto8[4] =
 32 {
 33    0, 0x55, 0xaa, 0xff
 34 };
 35 
 36 unsigned char oneto8[2] =
 37 {
 38    0, 255
 39 };
 40 
 41 static int defaultOverride[13] =
 42 {
 43    0, 3, 24, 27, 64, 67, 88, 173, 181, 236, 247, 164, 91
 44 };
 45 
 46 static PALETTEENTRY defaultPalEntry[20] =
 47 {
 48    { 0,   0,   0,    0 },
 49    { 0x80,0,   0,    0 },
 50    { 0,   0x80,0,    0 },
 51    { 0x80,0x80,0,    0 },
 52    { 0,   0,   0x80, 0 },
 53    { 0x80,0,   0x80, 0 },
 54    { 0,   0x80,0x80, 0 },
 55    { 0xC0,0xC0,0xC0, 0 },
 56 
 57    { 192, 220, 192,  0 },
 58    { 166, 202, 240,  0 },
 59    { 255, 251, 240,  0 },
 60    { 160, 160, 164,  0 },
 61 
 62    { 0x80,0x80,0x80, 0 },
 63    { 0xFF,0,   0,    0 },
 64    { 0,   0xFF,0,    0 },
 65    { 0xFF,0xFF,0,    0 },
 66    { 0,   0,   0xFF, 0 },
 67    { 0xFF,0,   0xFF, 0 },
 68    { 0,   0xFF,0xFF, 0 },
 69    { 0xFF,0xFF,0xFF, 0 }
 70 };
 71 
 72 /////////////////////////////////////////////////////////////////////////////
 73 // CCubeView
 74 
Top
  75 IMPLEMENT_DYNCREATE(CCubeView, CView)
  75   return new CCubeView
   75 }
Top
85988   75 FUNCTION CCubeView::_GetBaseClass()
85988   75   return ( CView::GetThisClass ( ) )
   75 }
Top
  75 FUNCTION CCubeView::GetThisClass()
  75   return ( ( CRuntimeClass * ) ( & CCubeView::classCCubeView ) )
   75 }
Top
209978   75 FUNCTION CCubeView::GetRuntimeClass()
209978   75   return ( ( CRuntimeClass * ) ( & CCubeView::classCCubeView ) )
   75 }
 76 
Top
42564   77 BEGIN_MESSAGE_MAP(CCubeView, CView)
42564   77   return GetThisMessageMap ( )
   77 }
Top
42564   77 FUNCTION CCubeView::GetThisMessageMap()
 78    //{{AFX_MSG_MAP(CCubeView)
 79    ON_COMMAND(ID_FILE_PLAY, OnFilePlay)
 80    ON_UPDATE_COMMAND_UI(ID_FILE_PLAY, OnUpdateFilePlay)
 81    ON_WM_CREATE()
 82    ON_WM_DESTROY()
 83    ON_WM_SIZE()
 84    ON_WM_TIMER()
 85    ON_WM_ERASEBKGND()
 86    //}}AFX_MSG_MAP
42564   87 END_MESSAGE_MAP()
   87 }
 88 
 89 /////////////////////////////////////////////////////////////////////////////
 90 // CCubeView construction/destruction
 91 
Top
  92 CCubeView::CCubeView()
 93 {
 94    m_pDC = NULL;
 95    m_pOldPalette = NULL;
 96    m_play = FALSE;
  97 }
 98 
Top
  99 CCubeView::~CCubeView()
 100 {
  101 }
 102 
 103 /////////////////////////////////////////////////////////////////////////////
 104 // CCubeView drawing
 105 
Top
274   106 void CCubeView::OnDraw(CDC* /*pDC*/)
 107 {
 108    CCubeDoc* pDoc = GetDocument();
 109    ASSERT_VALID(pDoc);
 110 
 111    DrawScene();
274   112 }
 113 
 114 /////////////////////////////////////////////////////////////////////////////
 115 // CCubeView diagnostics
 116 
 117 #ifdef _DEBUG
Top
117756   118 void CCubeView::AssertValid() const
 119 {
 120    CView::AssertValid();
117756   121 }
 122 
Top
 -123 void CCubeView::Dump(CDumpContext& dc) const
 124 {
 125    CView::Dump(dc);
 -126 }
 127 
Top
274   128 CCubeDoc* CCubeView::GetDocument() // non-debug version is inline
 129 {
274   130    return STATIC_DOWNCAST(CCubeDoc, m_pDocument);
   131 }
 132 #endif //_DEBUG
 133 
 134 /////////////////////////////////////////////////////////////////////////////
 135 // CCubeView message handlers
 136 
Top
16   137 void CCubeView::OnFilePlay()
 138 {
 139    m_play = m_play ? FALSE : TRUE;
 140    if (m_play)
 141       SetTimer(1, 15, NULL);
   142    else
 143       KillTimer(1);
16   144 }
 145 
Top
6224   146 void CCubeView::OnUpdateFilePlay(CCmdUI* pCmdUI)
 147 {
 148    pCmdUI->SetCheck(m_play);
6224   149 }
 150 
Top
  151 BOOL CCubeView::PreCreateWindow(CREATESTRUCT& cs)
 152 {
 153    // An OpenGL window must be created with the following flags and must not
 154    // include CS_PARENTDC for the class style. Refer to SetPixelFormat
 155    // documentation in the "Comments" section for further information.
 156    cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
 157 
  158    return CView::PreCreateWindow(cs);
   159 }
 160 
Top
  161 int CCubeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
 162 {
-163    if (CView::OnCreate(lpCreateStruct) == -1)
 -164       return -1;
 165 
 166    Init(); // initialize OpenGL
 167 
  168    return 0;
   169 }
 170 
Top
  171 void CCubeView::OnDestroy()
 172 {
 173    HGLRC   hrc;
 174 
 175    KillTimer(1);
 176 
 177    hrc = ::wglGetCurrentContext();
 178 
 179    ::wglMakeCurrent(NULL,  NULL);
 180 
-181    if (hrc)
 182       ::wglDeleteContext(hrc);
 183 
-184    if (m_pOldPalette)
 185       m_pDC->SelectPalette(m_pOldPalette, FALSE);
 186 
-187    if (m_pDC)
 188       delete m_pDC;
 189 
 190    CView::OnDestroy();
  191 }
 192 
Top
50   193 void CCubeView::OnSize(UINT nType, int cx, int cy)
 194 {
 195    CView::OnSize(nType, cx, cy);
 196 
48  197    if(cy > 0)
 198    {
 199       glViewport(0, 0, cx, cy);
 200 
29 19  201       if((m_oldRect.right > cx) || (m_oldRect.bottom > cy))
25   201       1: (T) || (_)
  201       2: (F) || (T)
 19  201       3: (F) || (F)
 202          RedrawWindow();
 203 
 204       m_oldRect.right = cx;
 205       m_oldRect.bottom = cy;
 206 
 207       glMatrixMode(GL_PROJECTION);
 208       glLoadIdentity();
 209       gluPerspective(45.0f, (GLdouble)cx/cy, 3.0f, 7.0f);
 210       glMatrixMode(GL_MODELVIEW);
 211    }
50   212 }
 213 
Top
2955   214 void CCubeView::OnTimer(UINT_PTR nIDEvent)
 215 {
 216    DrawScene();
 217 
 218    CView::OnTimer(nIDEvent);
 219 
 220    // Eat spurious WM_TIMER messages
 221    MSG msg;
50 2955  222    while(::PeekMessage(&msg, m_hWnd, WM_TIMER, WM_TIMER, PM_REMOVE));
2955   223 }
 224 
 225 /////////////////////////////////////////////////////////////////////////////
 226 // GL helper functions
 227 
Top
  228 void CCubeView::Init()
 229 {
 230    PIXELFORMATDESCRIPTOR pfd;
 231    int         n;
 232    HGLRC       hrc;
 233    GLfloat     fMaxObjSize, fAspect;
 234    GLfloat     fNearPlane, fFarPlane;
 235 
 236    m_pDC = new CClientDC(this);
 237 
 238    ASSERT(m_pDC != NULL);
 239 
-240    if (!bSetupPixelFormat())
 -241       return;
 242 
 243    n = ::GetPixelFormat(m_pDC->GetSafeHdc());
 244    ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
 245 
 246    CreateRGBPalette();
 247 
 248    hrc = wglCreateContext(m_pDC->GetSafeHdc());
 249    wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
 250 
 251    GetClientRect(&m_oldRect);
 252    glClearDepth(1.0f);
 253    glEnable(GL_DEPTH_TEST);
 254 
-255    if (m_oldRect.bottom)
 256       fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom;
   257    else    // don't divide by zero, not that we should ever run into that...
 258       fAspect = 1.0f;
 259    fNearPlane = 3.0f;
 260    fFarPlane = 7.0f;
 261    fMaxObjSize = 3.0f;
 262    m_fRadius = fNearPlane + fMaxObjSize / 2.0f;
 263 
 264    glMatrixMode(GL_PROJECTION);
 265    glLoadIdentity();
 266    gluPerspective(45.0f, fAspect, fNearPlane, fFarPlane);
 267    glMatrixMode(GL_MODELVIEW);
  268 }
 269 
Top
  270 BOOL CCubeView::bSetupPixelFormat()
 271 {
 272    static PIXELFORMATDESCRIPTOR pfd =
 273    {
 274       sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
 275       1,                              // version number
 276       PFD_DRAW_TO_WINDOW |            // support window
 277         PFD_SUPPORT_OPENGL |          // support OpenGL
 278         PFD_DOUBLEBUFFER,             // double buffered
 279       PFD_TYPE_RGBA,                  // RGBA type
 280       24,                             // 24-bit color depth
 281       0, 0, 0, 0, 0, 0,               // color bits ignored
 282       0,                              // no alpha buffer
 283       0,                              // shift bit ignored
 284       0,                              // no accumulation buffer
 285       0, 0, 0, 0,                     // accum bits ignored
 286       32,                             // 32-bit z-buffer
 287       0,                              // no stencil buffer
 288       0,                              // no auxiliary buffer
 289       PFD_MAIN_PLANE,                 // main layer
 290       0,                              // reserved
 291       0, 0, 0                         // layer masks ignored
 292    };
 293    int pixelformat;
 294 
-295    if ( (pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd)) == 0 )
 296    {
 297       MessageBox("ChoosePixelFormat failed");
 -298       return FALSE;
 299    }
 300 
-301    if (SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
 302    {
 303       MessageBox("SetPixelFormat failed");
 -304       return FALSE;
 305    }
 306 
  307    return TRUE;
   308 }
 309 
Top
 -310 unsigned char CCubeView::ComponentFromIndex(int i, UINT nbits, UINT shift)
 311 {
 312    unsigned char val;
 313 
 314    val = (unsigned char) (i >> shift);
   315    switch (nbits)
 316    {
 317 
 -318    case 1:
 319       val &= 0x1;
 -320       return oneto8[val];
 -321    case 2:
 322       val &= 0x3;
 -323       return twoto8[val];
 -324    case 3:
 325       val &= 0x7;
 -326       return threeto8[val];
 327 
 -328    default:
 -329       return 0;
 330    }
   331 }
 332 
 333 #pragma warning(disable : 4244)
Top
  334 void CCubeView::CreateRGBPalette()
 335 {
 336    PIXELFORMATDESCRIPTOR pfd;
 337    LOGPALETTE *pPal;
 338    int n, i;
 339 
 340    n = ::GetPixelFormat(m_pDC->GetSafeHdc());
 341    ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
 342 
-343    if (pfd.dwFlags & PFD_NEED_PALETTE)
 344    {
 345       n = 1 << pfd.cColorBits;
 346       pPal = (PLOGPALETTE) new char[sizeof(LOGPALETTE) + n * sizeof(PALETTEENTRY)];
 347 
 348       ASSERT(pPal != NULL);
 349 
 350       pPal->palVersion = 0x300;
 351       pPal->palNumEntries = n;
-352       for (i=0; i<n; i++)
 353       {
 354          pPal->palPalEntry[i].peRed =
 355                ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift);
 356          pPal->palPalEntry[i].peGreen =
 357                ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift);
 358          pPal->palPalEntry[i].peBlue =
 359                ComponentFromIndex(i, pfd.cBlueBits, pfd.cBlueShift);
 360          pPal->palPalEntry[i].peFlags = 0;
 361       }
 362 
 363       /* fix up the palette to include the default GDI palette */
 364       if ((pfd.cColorBits == 8)                           &&
 365          (pfd.cRedBits   == 3) && (pfd.cRedShift   == 0) &&
 366          (pfd.cGreenBits == 3) && (pfd.cGreenShift == 3) &&
-367          (pfd.cBlueBits  == 2) && (pfd.cBlueShift  == 6)
 -367       1: (T) && (T) && (T) && (T) && (T) && (T) && (T)
 -367       2: (T) && (T) && (T) && (T) && (T) && (T) && (F)
 -367       3: (T) && (T) && (T) && (T) && (T) && (F) && (_)
 -367       4: (T) && (T) && (T) && (T) && (F) && (_) && (_)
 -367       5: (T) && (T) && (T) && (F) && (_) && (_) && (_)
 -367       6: (T) && (T) && (F) && (_) && (_) && (_) && (_)
 -367       7: (T) && (F) && (_) && (_) && (_) && (_) && (_)
 -367       8: (F) && (_) && (_) && (_) && (_) && (_) && (_)
 368          )
 369       {
-370          for (i = 1 ; i <= 12 ; i++)
 371             pPal->palPalEntry[defaultOverride[i]] = defaultPalEntry[i];
 372       }
 373 
 374       m_cPalette.CreatePalette(pPal);
 375       delete [] pPal;
 376 
 377       m_pOldPalette = m_pDC->SelectPalette(&m_cPalette, FALSE);
 378       m_pDC->RealizePalette();
 379    }
  380 }
 381 #pragma warning(default : 4244)
 382 
Top
3229   383 void CCubeView::DrawScene(void)
 384 {
 385    static BOOL     bBusy = FALSE;
 386    static GLfloat  wAngleY = 10.0f;
 387    static GLfloat  wAngleX = 1.0f;
 388    static GLfloat  wAngleZ = 5.0f;
 389 
3229 -390    if(bBusy)
 -391       return;
 392    bBusy = TRUE;
 393 
 394    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 395    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 396 
 397    glPushMatrix();
 398 
 399       glTranslatef(0.0f, 0.0f, -m_fRadius);
 400       glRotatef(wAngleX, 1.0f, 0.0f, 0.0f);
 401       glRotatef(wAngleY, 0.0f, 1.0f, 0.0f);
 402       glRotatef(wAngleZ, 0.0f, 0.0f, 1.0f);
 403 
 404       wAngleX += 1.0f;
 405       wAngleY += 10.0f;
 406       wAngleZ += 5.0f;
 407 
 408 
 409       glBegin(GL_QUAD_STRIP);
 410          glColor3f(1.0f, 0.0f, 1.0f);
 411          glVertex3f(-0.5f, 0.5f, 0.5f);
 412 
 413          glColor3f(1.0f, 0.0f, 0.0f);
 414          glVertex3f(-0.5f, -0.5f, 0.5f);
 415 
 416          glColor3f(1.0f, 1.0f, 1.0f);
 417          glVertex3f(0.5f, 0.5f, 0.5f);
 418 
 419          glColor3f(1.0f, 1.0f, 0.0f);
 420          glVertex3f(0.5f, -0.5f, 0.5f);
 421 
 422          glColor3f(0.0f, 1.0f, 1.0f);
 423          glVertex3f(0.5f, 0.5f, -0.5f);
 424 
 425          glColor3f(0.0f, 1.0f, 0.0f);
 426          glVertex3f(0.5f, -0.5f, -0.5f);
 427 
 428          glColor3f(0.0f, 0.0f, 1.0f);
 429          glVertex3f(-0.5f, 0.5f, -0.5f);
 430 
 431          glColor3f(0.0f, 0.0f, 0.0f);
 432          glVertex3f(-0.5f, -0.5f,  -0.5f);
 433 
 434          glColor3f(1.0f, 0.0f, 1.0f);
 435          glVertex3f(-0.5f, 0.5f, 0.5f);
 436 
 437          glColor3f(1.0f, 0.0f, 0.0f);
 438          glVertex3f(-0.5f, -0.5f, 0.5f);
 439 
 440       glEnd();
 441 
 442       glBegin(GL_QUADS);
 443          glColor3f(1.0f, 0.0f, 1.0f);
 444          glVertex3f(-0.5f, 0.5f, 0.5f);
 445 
 446          glColor3f(1.0f, 1.0f, 1.0f);
 447          glVertex3f(0.5f, 0.5f, 0.5f);
 448 
 449          glColor3f(0.0f, 1.0f, 1.0f);
 450          glVertex3f(0.5f, 0.5f, -0.5f);
 451 
 452          glColor3f(0.0f, 0.0f, 1.0f);
 453          glVertex3f(-0.5f, 0.5f, -0.5f);
 454       glEnd();
 455 
 456       glBegin(GL_QUADS);
 457          glColor3f(1.0f, 0.0f, 0.0f);
 458          glVertex3f(-0.5f, -0.5f, 0.5f);
 459 
 460          glColor3f(1.0f, 1.0f, 0.0f);
 461          glVertex3f(0.5f, -0.5f, 0.5f);
 462 
 463          glColor3f(0.0f, 1.0f, 0.0f);
 464          glVertex3f(0.5f, -0.5f, -0.5f);
 465 
 466          glColor3f(0.0f, 0.0f, 0.0f);
 467          glVertex3f(-0.5f, -0.5f,  -0.5f);
 468       glEnd();
 469 
 470    glPopMatrix();
 471 
 472    glFinish();
 473    SwapBuffers(wglGetCurrentDC());
 474 
 475    bBusy = FALSE;
3229   476 }
 477 
Top
274   478 BOOL CCubeView::OnEraseBkgnd(CDC* /*pDC*/)
 479 {
274   480    return TRUE;
   481 }
***TER 63% (69/109) of SOURCE FILE cubeview.cpp
79% (155/196) statement

Directory Summary | Files Summary | Functions Summary | Untested Code | Execution Profile
To files: First | Previous | Next | Last | Top | Index | No Index