File: Wm5AglRendererData.cpp

package info (click to toggle)
libwildmagic 5.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 89,572 kB
  • ctags: 26,264
  • sloc: cpp: 210,924; csh: 637; sh: 95; makefile: 36
file content (134 lines) | stat: -rw-r--r-- 4,540 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.0.0 (2010/01/01)

#include "Wm5GraphicsPCH.h"
#include "Wm5AglRendererData.h"
#include "Wm5Renderer.h"
using namespace Wm5;

//----------------------------------------------------------------------------
void AglRendererData::LoadFont (const char* face, int size, bool fontBold,
    bool fontItalic)
{
    mFont.mQuantity = 256;
    mFont.mStart = glGenLists(mFont.mQuantity);
    mFont.mBase = 1;

    Str255 fontName;
    fontName[0] = (int)strlen(face);
    strcpy((char*)fontName + 1, face);

    short fontNum;
    GetFNum(fontName, &fontNum);

    Style style = normal;
    if (fontBold)
    {
        style |= bold;
    }
    if (fontItalic)
    {
        style |= italic;
    }

    if (!aglUseFont(mContext, fontNum, style, size,0, mFont.mQuantity,
        mFont.mStart))
    {
        glDeleteLists(mFont.mStart, mFont.mQuantity);
    }
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
}
//----------------------------------------------------------------------------
void AglRendererData::SetUpBufferRect (int winXPos, int winYPos,
    int winWidth, int winHeight)
{
    // If the context is smaller than the underlying surface, we clip it.
    CGrafPtr port = aglGetDrawable(mContext);
    Rect portRect = { 0 };
    GetPortBounds(port, &portRect);
    int portWidth = portRect.right - portRect.left;
    int portHeight = portRect.bottom - portRect.top;
    if (portWidth != winWidth || portHeight != winHeight)
    {
        int height = portHeight + 1;
        int y = height - winYPos;
        if (--y < 0)
        {
            y = 0;
        }
        GLint rect[4] = { winXPos, y - winHeight, winWidth, winHeight };
        if (!aglSetInteger(mContext, AGL_BUFFER_RECT, rect))
        {
            FatalErrorMessage("Cannot assign AGL_BUFFER_RECT.");
        }
        if (!aglEnable(mContext, AGL_BUFFER_RECT))
        {
            FatalErrorMessage("Cannot enable AGL_BUFFER_RECT.");
        }
        aglUpdateContext(mContext);
    }
    else
    {
        if (!aglDisable(mContext, AGL_BUFFER_RECT))
        {
            FatalErrorMessage("Cannot disable AGL_BUFFER_RECT.");
        }
        aglUpdateContext(mContext);
    }
}
//----------------------------------------------------------------------------
void AglRendererData::Finalize (Renderer* renderer)
{
    // Select the shader profiles.
    VertexShader::SetProfile(VertexShader::VP_ARBVP1);
    PixelShader::SetProfile(PixelShader::PP_ARBFP1);

    // Query the device for its capabilities.  TODO:  The number of images
    // turns out to be larger than what Shader Model 3 supports.  Why is this?
    mMaxVShaderImages = 0;
    mMaxPShaderImages = 0;
    mMaxCombinedImages = 0;
    glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVShaderImages);
    glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxPShaderImages);
    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedImages);

    // Set the default render states.
    mCurrentRS.Initialize(renderer->GetAlphaState(), renderer->GetCullState(),
        renderer->GetDepthState(), renderer->GetOffsetState(),
        renderer->GetStencilState(), renderer->GetWireState());
}
//----------------------------------------------------------------------------
void AglRendererData::FatalErrorMessage (const char* message)
{
    if (mDSpContext)
    {
        DSpContextState contextState;
        if (DSpContext_GetState(mDSpContext, &contextState) == noErr
        &&  contextState == kDSpContextState_Active)
        {
            DSpContext_SetState(mDSpContext, kDSpContextState_Inactive);
            DSpContext_Release(mDSpContext);
        }
    }

    char header[256];
    GLenum error = aglGetError();
    sprintf(header, "AglRenderer encountered error %ld.", (long)error);
    Str255 strHeader;
    strHeader[0] = strlen(header);
    strncpy((char*)strHeader + 1, header, strHeader[0]);

    int length = strlen(message);
    Str255 strMessage;
    strMessage[0] = length;
    strncpy((char*)strMessage + 1, message, length);
    SInt16 item;
    StandardAlert(kAlertStopAlert, strHeader, strMessage,0, &item);
    ExitToShell();
}
//----------------------------------------------------------------------------