summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/common/crOpenGL/pack/packspu_beginend.py
blob: 2195cab58c4d22cc72c98f895fc06c1778393926 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.

from __future__ import print_function
import sys

import apiutil


apiutil.CopyrightC()

print("""/* DO NOT EDIT - AUTOMATICALLY GENERATED BY packspu_beginend.py */
#include "packspu.h"
#include "assert.h"
#include "cr_packfunctions.h"
#include "packspu_proto.h"

void PACKSPU_APIENTRY packspu_Begin( GLenum mode )
{
    CRPackBuffer *buf;
#if CR_ARB_vertex_buffer_object
    GET_CONTEXT(ctx);
#else
    GET_THREAD(thread);
#endif

    buf = &thread->BeginEndBuffer;

    /* XXX comparing mode >= 0 here is not needed since mode is unsigned */
    CRASSERT( /*mode >= GL_POINTS && */mode <= GL_POLYGON );

#if CR_ARB_vertex_buffer_object
    {
        GLboolean serverArrays = GL_FALSE;
        if (ctx->clientState->extensions.ARB_vertex_buffer_object)
            serverArrays = crStateUseServerArrays();
        if (serverArrays) {
            CRClientState *clientState = &(ctx->clientState->client);
            if (clientState->array.locked && !clientState->array.synced)
            {
                crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
                clientState->array.synced = GL_TRUE;
            }
        }
    }
#endif

    if (pack_spu.swap)
    {
        crPackBeginSWAP( mode );
    }
    else
    {
        crPackBegin( mode );
    }

    if ( thread->netServer.conn->Barf ) {
        thread->BeginEndMode = mode;
        thread->BeginEndState = -1;
        if ( mode == GL_LINES || mode == GL_TRIANGLES || mode == GL_QUADS || mode == GL_POLYGON )
        {
            CRASSERT(!buf->pack);

            crPackReleaseBuffer( thread->packer );
            buf->pack = crNetAlloc( thread->netServer.conn );
            crPackInitBuffer( buf, buf->pack, thread->netServer.conn->buffer_size, thread->netServer.conn->mtu );
            buf->holds_BeginEnd = 1;
            buf->in_BeginEnd = 1;
            crPackSetBuffer( thread->packer, buf );

            thread->BeginEndState = 0;
        }
    }
}

void PACKSPU_APIENTRY packspu_End( void )
{
    GET_THREAD(thread);
    CRPackBuffer *buf = &thread->BeginEndBuffer;

    if ( thread->netServer.conn->Barf &&
        (thread->BeginEndMode == GL_LINES
        || thread->BeginEndMode == GL_TRIANGLES
        || thread->BeginEndMode == GL_QUADS
        || thread->BeginEndMode == GL_POLYGON ) )
    {
        CRASSERT(buf->pack);

        crPackReleaseBuffer( thread->packer );
        crPackSetBuffer( thread->packer, &thread->normBuffer );
        if ( !crPackCanHoldBuffer( buf ) )
            packspuFlush( (void *) thread );

        crPackAppendBuffer( buf );
        crNetFree( thread->netServer.conn, buf->pack );
        buf->pack = NULL;
    }

    if (pack_spu.swap)
    {
        crPackEndSWAP();
    }
    else
    {
        crPackEnd();
    }
}

static void DoVertex( void )
{
    GET_THREAD(thread);
    CRPackBuffer *buf = &thread->BeginEndBuffer;
    CRPackBuffer *gbuf = &thread->normBuffer;
    int num_data;
    int num_opcode;

    /*crDebug( "really doing Vertex" );*/
    crPackReleaseBuffer( thread->packer );
    num_data = buf->data_current - buf->data_start;
    num_opcode = buf->opcode_start - buf->opcode_current;
    crPackSetBuffer( thread->packer, gbuf );
    if ( !crPackCanHoldBuffer( buf ) )
        /* doesn't hold, first flush gbuf*/
        packspuFlush( (void *) thread );

    crPackAppendBuffer( buf );
    crPackReleaseBuffer( thread->packer );
    crPackSetBuffer( thread->packer, buf );
    crPackResetPointers(thread->packer);
}

static void RunState( void )
{
    GET_THREAD(thread);
    if (! thread->netServer.conn->Barf ) return;
    if (thread->BeginEndState == -1) return;
    switch(thread->BeginEndMode) {
    case GL_POLYGON:
        return;
    case GL_LINES:
        thread->BeginEndState = (thread->BeginEndState + 1) % 2;
        if (thread->BeginEndState)
            return;
        break;
    case GL_TRIANGLES:
        thread->BeginEndState = (thread->BeginEndState + 1) % 3;
        if (thread->BeginEndState)
            return;
        break;
    case GL_QUADS:
        thread->BeginEndState = (thread->BeginEndState + 1) % 4;
        if (thread->BeginEndState)
            return;
        break;
    }
    DoVertex();
}
""")

keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")

for func_name in apiutil.AllSpecials( "packspu_vertex" ):
    params = apiutil.Parameters(func_name)
    print('void PACKSPU_APIENTRY packspu_%s(%s)' % ( func_name, apiutil.MakeDeclarationString(params) ))
    print('{')
    print('\tif (pack_spu.swap)')
    print('\t{')
    print('\t\tcrPack%sSWAP(%s);' % ( func_name, apiutil.MakeCallString( params ) ))
    print('\t}')
    print('\telse')
    print('\t{')
    print('\t\tcrPack%s(%s);' % ( func_name, apiutil.MakeCallString( params ) ))
    print('\t}')
    print('\tRunState();')
    print('}')