Home | History | Annotate | Download | only in compiler
      1 //
      2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 #include "compiler/InitializeGLPosition.h"
      8 #include "compiler/debug.h"
      9 
     10 bool InitializeGLPosition::visitAggregate(Visit visit, TIntermAggregate* node)
     11 {
     12     bool visitChildren = !mCodeInserted;
     13     switch (node->getOp())
     14     {
     15       case EOpSequence: break;
     16       case EOpFunction:
     17       {
     18         // Function definition.
     19         ASSERT(visit == PreVisit);
     20         if (node->getName() == "main(")
     21         {
     22             TIntermSequence &sequence = node->getSequence();
     23             ASSERT((sequence.size() == 1) || (sequence.size() == 2));
     24             TIntermAggregate *body = NULL;
     25             if (sequence.size() == 1)
     26             {
     27                 body = new TIntermAggregate(EOpSequence);
     28                 sequence.push_back(body);
     29             }
     30             else
     31             {
     32                 body = sequence[1]->getAsAggregate();
     33             }
     34             ASSERT(body);
     35             insertCode(body->getSequence());
     36             mCodeInserted = true;
     37         }
     38         break;
     39       }
     40       default: visitChildren = false; break;
     41     }
     42     return visitChildren;
     43 }
     44 
     45 void InitializeGLPosition::insertCode(TIntermSequence& sequence)
     46 {
     47     TIntermBinary *binary = new TIntermBinary(EOpAssign);
     48     sequence.insert(sequence.begin(), binary);
     49 
     50     TIntermSymbol *left = new TIntermSymbol(
     51         0, "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4));
     52     binary->setLeft(left);
     53 
     54     ConstantUnion *u = new ConstantUnion[4];
     55     for (int ii = 0; ii < 3; ++ii)
     56         u[ii].setFConst(0.0f);
     57     u[3].setFConst(1.0f);
     58     TIntermConstantUnion *right = new TIntermConstantUnion(
     59         u, TType(EbtFloat, EbpUndefined, EvqConst, 4));
     60     binary->setRight(right);
     61 }
     62