Skip to content

Commit fc9c22c

Browse files
committed
Remove the GLState class.
1 parent 29f581c commit fc9c22c

File tree

8 files changed

+4
-1303
lines changed

8 files changed

+4
-1303
lines changed

Diff for: tgfx/src/gpu/opengl/GLContext.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
#include "gpu/opengl/GLDevice.h"
2121

2222
namespace tgfx {
23-
GLContext::GLContext(Device* device, const GLInterface* glInterface) : Context(device) {
24-
glState = std::make_unique<GLState>(glInterface);
25-
interface = GLInterface::HookWithState(glInterface, glState.get());
23+
GLContext::GLContext(Device* device, const GLInterface* glInterface)
24+
: Context(device), interface(glInterface) {
2625
}
2726
} // namespace tgfx

Diff for: tgfx/src/gpu/opengl/GLContext.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#pragma once
2020

2121
#include "GLInterface.h"
22-
#include "GLState.h"
2322
#include "gpu/Context.h"
2423

2524
namespace tgfx {
@@ -42,8 +41,7 @@ class GLContext : public Context {
4241
}
4342

4443
private:
45-
std::unique_ptr<const GLInterface> interface = nullptr;
46-
std::unique_ptr<GLState> glState = nullptr;
44+
const GLInterface* interface = nullptr;
4745

4846
friend class GLDevice;
4947
friend class GLInterface;

Diff for: tgfx/src/gpu/opengl/GLDevice.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ bool GLDevice::onLockContext() {
6666
onClearCurrent();
6767
return false;
6868
}
69-
auto glContext = static_cast<GLContext*>(context);
70-
if (isAdopted) {
71-
glContext->glState->reset();
72-
// Clear externally generated GLError.
73-
CheckGLError(glContext->interface.get());
74-
}
7569
return true;
7670
}
7771

Diff for: tgfx/src/gpu/opengl/GLInterface.cpp

+1-46
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
/////////////////////////////////////////////////////////////////////////////////////////////////
1818

1919
#include "GLInterface.h"
20-
2120
#include <mutex>
2221
#include <unordered_map>
2322
#include "GLAssembledGLESInterface.h"
2423
#include "GLAssembledGLInterface.h"
2524
#include "GLAssembledWebGLInterface.h"
26-
#include "GLState.h"
2725
#include "GLUtil.h"
2826

2927
namespace tgfx {
@@ -43,7 +41,7 @@ static int GetGLVersion(const GLProcGetter* getter) {
4341
}
4442

4543
const GLInterface* GLInterface::Get(const Context* context) {
46-
return context ? static_cast<const GLContext*>(context)->interface.get() : nullptr;
44+
return context ? static_cast<const GLContext*>(context)->interface : nullptr;
4745
}
4846

4947
const GLInterface* GLInterface::GetNative() {
@@ -64,49 +62,6 @@ const GLInterface* GLInterface::GetNative() {
6462
return glInterfaceMap[version].get();
6563
}
6664

67-
namespace {
68-
template <typename R, typename... Args>
69-
GLFunction<R GL_FUNCTION_TYPE(Args...)> Bind(GLState* interface, R (GLState::*member)(Args...)) {
70-
return [interface, member](Args... a) -> R { return (interface->*member)(a...); };
71-
}
72-
} // anonymous namespace
73-
74-
#ifdef TGFX_BUILD_FOR_WEB
75-
#define Hook(X) state
76-
#else
77-
#define Hook(X) functions->X = Bind(state, &GLState::X)
78-
#endif
79-
80-
std::unique_ptr<const GLInterface> GLInterface::HookWithState(const GLInterface* gl,
81-
GLState* state) {
82-
auto functions = std::make_shared<GLFunctions>();
83-
*functions = *gl->functions;
84-
Hook(activeTexture);
85-
Hook(blendEquation);
86-
Hook(blendFunc);
87-
Hook(bindFramebuffer);
88-
Hook(bindRenderbuffer);
89-
Hook(bindBuffer);
90-
Hook(bindTexture);
91-
Hook(disable);
92-
Hook(disableVertexAttribArray);
93-
Hook(enable);
94-
Hook(enableVertexAttribArray);
95-
Hook(pixelStorei);
96-
Hook(scissor);
97-
Hook(viewport);
98-
Hook(useProgram);
99-
Hook(vertexAttribPointer);
100-
Hook(depthMask);
101-
if (gl->caps->vertexArrayObjectSupport) {
102-
Hook(bindVertexArray);
103-
}
104-
auto interface = new GLInterface();
105-
interface->functions = functions;
106-
interface->caps = gl->caps;
107-
return std::unique_ptr<const GLInterface>(interface);
108-
}
109-
11065
std::unique_ptr<const GLInterface> GLInterface::MakeNativeInterface(const GLProcGetter* getter) {
11166
if (getter == nullptr) {
11267
return nullptr;

Diff for: tgfx/src/gpu/opengl/GLInterface.h

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class GLInterface {
3636
private:
3737
static const GLInterface* GetNative();
3838
static std::unique_ptr<const GLInterface> MakeNativeInterface(const GLProcGetter* getter);
39-
static std::unique_ptr<const GLInterface> HookWithState(const GLInterface* gl, GLState* state);
4039

4140
friend class GLDevice;
4241
friend class GLContext;

Diff for: tgfx/src/gpu/opengl/GLRenderTarget.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "gpu/opengl/GLRenderTarget.h"
2020
#include "core/Bitmap.h"
2121
#include "gpu/opengl/GLContext.h"
22-
#include "gpu/opengl/GLState.h"
2322
#include "gpu/opengl/GLUtil.h"
2423

2524
namespace tgfx {

0 commit comments

Comments
 (0)