ppsspp/GPU/GLES/DrawEngineGLES.h

171 lines
4.7 KiB
C
Raw Normal View History

2012-11-01 15:19:01 +00:00
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
2012-11-01 15:19:01 +00:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "Common/Data/Collections/Hashmaps.h"
#include "Common/GPU/OpenGL/GLCommon.h"
#include "Common/GPU/OpenGL/GLRenderManager.h"
#include "GPU/GPUState.h"
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Common/IndexGenerator.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "GPU/Common/GPUStateUtils.h"
#include "GPU/Common/FragmentShaderGenerator.h"
class LinkedShader;
class ShaderManagerGLES;
class TextureCacheGLES;
class FramebufferManagerGLES;
class FramebufferManagerCommon;
2014-09-13 11:15:18 +00:00
class TextureCacheCommon;
class FragmentTestCacheGLES;
2014-03-29 23:51:38 +00:00
struct TransformedVertex;
struct DecVtxFormat;
enum {
TEX_SLOT_PSP_TEXTURE = 0,
TEX_SLOT_SHADERBLEND_SRC = 1,
TEX_SLOT_ALPHATEST = 2,
TEX_SLOT_CLUT = 3,
TEX_SLOT_SPLINE_POINTS = 4,
TEX_SLOT_SPLINE_WEIGHTS_U = 5,
TEX_SLOT_SPLINE_WEIGHTS_V = 6,
};
class TessellationDataTransferGLES : public TessellationDataTransfer {
private:
GLRTexture *data_tex[3]{};
int prevSizeU = 0, prevSizeV = 0;
int prevSizeWU = 0, prevSizeWV = 0;
GLRenderManager *renderManager_;
public:
TessellationDataTransferGLES(GLRenderManager *renderManager)
: renderManager_(renderManager) { }
~TessellationDataTransferGLES() {
EndFrame();
}
// Send spline/bezier's control points and weights to vertex shader through floating point texture.
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
void EndFrame(); // Queues textures for deletion.
};
// Handles transform, lighting and drawing.
class DrawEngineGLES : public DrawEngineCommon {
public:
2017-11-18 23:43:58 +00:00
DrawEngineGLES(Draw::DrawContext *draw);
virtual ~DrawEngineGLES();
void SetShaderManager(ShaderManagerGLES *shaderManager) {
2012-12-25 14:28:34 +00:00
shaderManager_ = shaderManager;
}
void SetTextureCache(TextureCacheGLES *textureCache) {
2013-01-30 19:40:26 +00:00
textureCache_ = textureCache;
}
void SetFramebufferManager(FramebufferManagerGLES *fbManager) {
framebufferManager_ = fbManager;
}
void SetFragmentTestCache(FragmentTestCacheGLES *testCache) {
fragmentTestCache_ = testCache;
}
2017-12-09 22:58:08 +00:00
void DeviceLost();
void DeviceRestore(Draw::DrawContext *draw);
void ClearTrackedVertexArrays() override {}
2017-11-19 11:25:57 +00:00
void BeginFrame();
void EndFrame();
2013-08-10 23:25:14 +00:00
// So that this can be inlined
void Flush() {
if (!numDrawCalls)
return;
DoFlush();
}
void FinishDeferred() {
if (!numDrawCalls)
return;
2017-11-19 16:37:56 +00:00
DoFlush();
}
2014-03-29 23:51:38 +00:00
bool IsCodePtrVertexDecoder(const u8 *ptr) const;
void DispatchFlush() override { Flush(); }
2014-09-14 21:04:09 +00:00
GLPushBuffer *GetPushVertexBuffer() {
return frameData_[render_->GetCurFrame()].pushVertex;
}
GLPushBuffer *GetPushIndexBuffer() {
return frameData_[render_->GetCurFrame()].pushIndex;
}
2017-11-19 11:25:57 +00:00
void ClearInputLayoutMap();
bool SupportsHWTessellation() const;
protected:
bool UpdateUseHWTessellation(bool enable) override;
void DecimateTrackedVertexArrays() {}
private:
2017-12-09 22:58:08 +00:00
void InitDeviceObjects();
void DestroyDeviceObjects();
2013-08-10 23:25:14 +00:00
void DoFlush();
2013-01-30 19:40:26 +00:00
void ApplyDrawState(int prim);
2017-12-12 14:04:46 +00:00
void ApplyDrawStateLate(bool setStencil, int stencilValue);
void ResetFramebufferRead();
2017-11-19 11:25:57 +00:00
GLRInputLayout *SetupDecFmtForDraw(LinkedShader *program, const DecVtxFormat &decFmt);
void *DecodeVertsToPushBuffer(GLPushBuffer *push, uint32_t *bindOffset, GLRBuffer **buf);
2017-11-19 11:25:57 +00:00
struct FrameData {
GLPushBuffer *pushVertex;
GLPushBuffer *pushIndex;
};
FrameData frameData_[GLRenderManager::MAX_INFLIGHT_FRAMES];
DenseHashMap<uint32_t, GLRInputLayout *, nullptr> inputLayoutMap_;
GLRInputLayout *softwareInputLayout_ = nullptr;
GLRenderManager *render_;
// Other
2017-06-02 10:03:46 +00:00
ShaderManagerGLES *shaderManager_ = nullptr;
TextureCacheGLES *textureCache_ = nullptr;
FramebufferManagerGLES *framebufferManager_ = nullptr;
FragmentTestCacheGLES *fragmentTestCache_ = nullptr;
2017-11-18 23:43:58 +00:00
Draw::DrawContext *draw_;
2017-06-02 10:03:46 +00:00
// Need to preserve the scissor for use when clearing.
ViewportAndScissor vpAndScissor;
2017-06-02 10:03:46 +00:00
int bufferDecimationCounter_ = 0;
int lastRenderStepId_ = -1;
// Hardware tessellation
TessellationDataTransferGLES *tessDataTransferGLES;
};