~ubuntu-branches/ubuntu/raring/glmark2/raring

« back to all changes in this revision

Viewing changes to src/scene-ideas/characters.h

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2012-08-21 15:38:09 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120821153809-bwux72bat8qp2n5v
Tags: 2012.08-0ubuntu1
* New upstream release 2012.08 (LP: #1039736)
  - Avoid crashing if gl used is not >= 2.0 (LP: #842279)
* Bumping dh compatibility level to v9
* debian/control:
  - Update Standards-Version to 3.9.3.
  - Add libjpeg-dev build dependency.
  - Use libegl1-x11-dev as an build-dep alternative instead of libegl1-dev.
  - Update description of glmark2-data binary package.
* debian/copyright:
  - Refresh copyright based on the current upstrem version
* debian/rules:
  - Clean compiled python code from unpacked waflib/ directory, as
    described in http://wiki.debian.org/UnpackWaf

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * (c) Copyright 1993, Silicon Graphics, Inc.
 
3
 * Copyright � 2012 Linaro Limited
 
4
 *
 
5
 * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
 
6
 *
 
7
 * glmark2 is free software: you can redistribute it and/or modify it under the
 
8
 * terms of the GNU General Public License as published by the Free Software
 
9
 * Foundation, either version 3 of the License, or (at your option) any later
 
10
 * version.
 
11
 *
 
12
 * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
 
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
15
 * details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along with
 
18
 * glmark2.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 * Authors:
 
21
 *  Jesse Barker
 
22
 */
 
23
#ifndef CHARACTERS_H_
 
24
#define CHARACTERS_H_
 
25
 
 
26
#include <vector>
 
27
#include "vec.h"
 
28
#include "gl-headers.h"
 
29
 
 
30
class PrimitiveState
 
31
{
 
32
public:
 
33
    PrimitiveState(unsigned int type, unsigned int count, unsigned int offset) :
 
34
        type_(type),
 
35
        count_(count),
 
36
        bufferOffset_(offset) {}
 
37
    ~PrimitiveState() {}
 
38
    void issue() const
 
39
    {
 
40
        glDrawElements(type_, count_, GL_UNSIGNED_SHORT, 
 
41
            reinterpret_cast<const GLvoid*>(bufferOffset_));
 
42
    }
 
43
private:
 
44
    PrimitiveState();
 
45
    unsigned int type_;         // Primitive type (e.g. GL_TRIANGLE_STRIP)
 
46
    unsigned int count_;        // Number of primitives
 
47
    unsigned int bufferOffset_; // Offset into the element array buffer
 
48
};
 
49
 
 
50
struct Character
 
51
{
 
52
    void draw()
 
53
    {
 
54
        glBindBuffer(GL_ARRAY_BUFFER, bufferObjects_[0]);
 
55
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects_[1]);
 
56
        glVertexAttribPointer(vertexIndex_, 2, GL_FLOAT, GL_FALSE, 0, 0);
 
57
        glEnableVertexAttribArray(vertexIndex_);
 
58
        for (std::vector<PrimitiveState>::const_iterator primIt = primVec_.begin();
 
59
             primIt != primVec_.end();
 
60
             primIt++)
 
61
        {
 
62
            primIt->issue();
 
63
        }
 
64
        glBindBuffer(GL_ARRAY_BUFFER, 0);
 
65
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 
66
    }
 
67
    void init(int vertexAttribIndex) 
 
68
    {
 
69
        vertexIndex_ = vertexAttribIndex;
 
70
 
 
71
        // We need 2 buffers for our work here.  One for the vertex data.
 
72
        // and one for the index data.
 
73
        glGenBuffers(2, &bufferObjects_[0]);
 
74
 
 
75
        // First, setup the vertex data by binding the first buffer object, 
 
76
        // allocating its data store, and filling it in with our vertex data.
 
77
        glBindBuffer(GL_ARRAY_BUFFER, bufferObjects_[0]);
 
78
        glBufferData(GL_ARRAY_BUFFER, vertexData_.size() * sizeof(LibMatrix::vec2), 
 
79
            &vertexData_.front(), GL_STATIC_DRAW);
 
80
 
 
81
        // Finally, setup the pointer to our vertex data and enable this
 
82
        // attribute array.
 
83
        glVertexAttribPointer(vertexIndex_, 2, GL_FLOAT, GL_FALSE, 0, 0);
 
84
        glEnableVertexAttribArray(vertexIndex_);
 
85
 
 
86
        // Now repeat for our index data.
 
87
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects_[1]);
 
88
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, 
 
89
            indexData_.size() * sizeof(unsigned short), &indexData_.front(), 
 
90
            GL_STATIC_DRAW);
 
91
 
 
92
        // Unbind our vertex buffer objects so that their state isn't affected
 
93
        // by other objects.
 
94
        glBindBuffer(GL_ARRAY_BUFFER, 0);
 
95
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 
96
    }
 
97
    ~Character()
 
98
    {
 
99
        glDeleteBuffers(2, &bufferObjects_[0]);
 
100
    }
 
101
    Character() :
 
102
        vertexIndex_(0),
 
103
        vertexArray_(0) {}
 
104
    unsigned int bufferObjects_[2];
 
105
    std::vector<LibMatrix::vec2> vertexData_;
 
106
    std::vector<unsigned short> indexData_;
 
107
    int vertexIndex_;
 
108
    unsigned int vertexArray_;
 
109
    std::vector<PrimitiveState> primVec_;
 
110
};
 
111
 
 
112
struct LetterI : Character
 
113
{
 
114
    LetterI();
 
115
};
 
116
 
 
117
struct LetterD : Character
 
118
{
 
119
    LetterD();
 
120
};
 
121
 
 
122
struct LetterE : Character
 
123
{
 
124
    LetterE();
 
125
};
 
126
 
 
127
struct LetterA : Character
 
128
{
 
129
    LetterA();
 
130
};
 
131
 
 
132
struct LetterS : Character
 
133
{
 
134
    LetterS();
 
135
};
 
136
 
 
137
struct LetterN : Character
 
138
{
 
139
    LetterN();
 
140
};
 
141
 
 
142
struct LetterM : Character
 
143
{
 
144
    LetterM();
 
145
};
 
146
 
 
147
struct LetterO : Character
 
148
{
 
149
    LetterO();
 
150
};
 
151
 
 
152
struct LetterT : Character
 
153
{
 
154
    LetterT();
 
155
};
 
156
 
 
157
#endif // CHARACTERS_H_