PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
clear.cpp
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#include "ps2s/math.h"
8#include "ps2s/packet.h"
9
10#include "ps2gl/clear.h"
11#include "ps2gl/drawcontext.h"
12#include "ps2gl/glcontext.h"
13#include "ps2gl/immgmanager.h"
14
15CClearEnv::CClearEnv()
16{
17 pDrawEnv = new GS::CDrawEnv(GS::kContext2);
18 pDrawEnv->SetDepthTestPassMode(GS::ZTest::kAlways);
19
20 pSprite = new CSprite(GS::kContext2, 0, 0, 0, 0);
21 pSprite->SetUseTexture(false);
22 unsigned int clearColor[4] = { 0, 0, 0, 0 };
23 pSprite->SetColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
24 pSprite->SetDepth(0);
25}
26
27CClearEnv::~CClearEnv()
28{
29 delete pDrawEnv;
30 delete pSprite;
31}
32
33void CClearEnv::SetDimensions(int width, int height)
34{
35 pDrawEnv->SetFrameBufferDim(width, height);
36 pSprite->SetVertices(0, 0, width, height);
37}
38
39void CClearEnv::SetFrameBufPsm(GS::tPSM psm)
40{
41 pDrawEnv->SetFrameBufferPSM(psm);
42}
43
44void CClearEnv::SetDepthBufPsm(GS::tPSM psm)
45{
46 pDrawEnv->SetDepthBufferPSM(psm);
47}
48
49void CClearEnv::ClearBuffers(unsigned int bitMask)
50{
51 if (bitMask & GL_DEPTH_BUFFER_BIT)
52 pDrawEnv->EnableDepthTest();
53 else
54 pDrawEnv->DisableDepthTest();
55
56 if (bitMask & GL_COLOR_BUFFER_BIT)
57 pDrawEnv->SetFrameBufferDrawMask(0);
58 else
59 pDrawEnv->SetFrameBufferDrawMask(0xffffffff);
60
61 CVifSCDmaPacket& packet = pGLContext->GetVif1Packet();
62 pGLContext->AddingDrawEnvToPacket((tU128*)pGLContext->GetVif1Packet().GetNextPtr() + 1);
63 pDrawEnv->SendSettings(packet);
64 pSprite->Draw(packet);
65}
66
67/********************************************
68 * C gl api
69 */
70
71void glClearColor(GLclampf red,
72 GLclampf green,
73 GLclampf blue,
74 GLclampf alpha)
75{
76 GL_FUNC_DEBUG("%s(%f,%f,%f,%f)\n", __FUNCTION__, red, green, blue, alpha);
77
78 CClearEnv& clearEnv = pGLContext->GetImmDrawContext().GetClearEnv();
79
80 using namespace Math;
81 clearEnv.SetClearColor(Clamp(red, 0.0f, 1.0f),
82 Clamp(green, 0.0f, 1.0f),
83 Clamp(blue, 0.0f, 1.0f),
84 Clamp(alpha, 0.0f, 1.0f));
85}
86
87void glClearDepth(GLclampd depth)
88{
89 GL_FUNC_DEBUG("%s(%f)\n", __FUNCTION__, depth);
90
91 CClearEnv& clearEnv = pGLContext->GetImmDrawContext().GetClearEnv();
92
93 clearEnv.SetClearDepth((float)depth);
94}
95
96void glClear(GLbitfield mask)
97{
98 GL_FUNC_DEBUG("%s(0x%x)\n", __FUNCTION__, mask);
99
100 pGLContext->GetImmDrawContext().GetClearEnv().ClearBuffers(mask);
101}