diff options
-rw-r--r-- | Documents/代码.xlsx | bin | 0 -> 9235 bytes | |||
-rw-r--r-- | Runtime/Graphics/OpenGL.cpp | 4 | ||||
-rw-r--r-- | Runtime/Graphics/OpenGL.h | 16 | ||||
-rw-r--r-- | Runtime/Graphics/Texture.cpp | 19 | ||||
-rw-r--r-- | Runtime/Graphics/Texture.h | 7 | ||||
-rw-r--r-- | Runtime/Scripting/Rendering/Texture.bind.cpp | 3 |
6 files changed, 47 insertions, 2 deletions
diff --git a/Documents/代码.xlsx b/Documents/代码.xlsx Binary files differnew file mode 100644 index 0000000..676d9d1 --- /dev/null +++ b/Documents/代码.xlsx diff --git a/Runtime/Graphics/OpenGL.cpp b/Runtime/Graphics/OpenGL.cpp index e0dc8f1..9ed2e50 100644 --- a/Runtime/Graphics/OpenGL.cpp +++ b/Runtime/Graphics/OpenGL.cpp @@ -1,3 +1,7 @@ #include "OpenGL.h" #pragma comment(lib, "opengl32.lib") + +std::string g_sharedGLErrorMsg = ""; + + diff --git a/Runtime/Graphics/OpenGL.h b/Runtime/Graphics/OpenGL.h index dcecb6d..69755e1 100644 --- a/Runtime/Graphics/OpenGL.h +++ b/Runtime/Graphics/OpenGL.h @@ -2,7 +2,23 @@ #define OPENGL_H #include "glad/glad.h" +#include <string> +#include <exception> //http://docs.gl/gl3/glClear +#define CheckGLError(action)\ +if(true){ \ + GLenum error; \ + while ((error = glGetError()) != GL_NO_ERROR) { \ + action \ + } \ +} + +class GLException : std::exception +{ +}; + +extern std::string g_sharedGLErrorMsg; + #endif diff --git a/Runtime/Graphics/Texture.cpp b/Runtime/Graphics/Texture.cpp index ce09927..8f4f245 100644 --- a/Runtime/Graphics/Texture.cpp +++ b/Runtime/Graphics/Texture.cpp @@ -16,6 +16,12 @@ Texture::Texture(LuaBind::VM* vm, TextureSetting setting, ImageData* imgData) glGenTextures(1, &m_GPUID);
glBindTexture(GL_TEXTURE_2D, m_GPUID);
+
+ CheckGLError(
+ glDeleteTextures(1, &m_GPUID);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ throw TextureException(error);
+ );
switch (m_WrapMode) {
case ETextureWrapMode::Clamp:
@@ -36,6 +42,12 @@ Texture::Texture(LuaBind::VM* vm, TextureSetting setting, ImageData* imgData) break;
}
+ CheckGLError(
+ glDeleteTextures(1, &m_GPUID);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ throw TextureException(error);
+ );
+
switch (m_FilterMode) {
case ETextureFilterMode::Linear:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -53,6 +65,12 @@ Texture::Texture(LuaBind::VM* vm, TextureSetting setting, ImageData* imgData) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgData->width, imgData->height, 0, GL_RGB, GL_UNSIGNED_BYTE, imgData->pixels);
+ CheckGLError(
+ glDeleteTextures(1, &m_GPUID);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ throw TextureException(error);
+ );
+
// keep image data ?
if (m_KeepPixelData)
{
@@ -61,6 +79,7 @@ Texture::Texture(LuaBind::VM* vm, TextureSetting setting, ImageData* imgData) SetMemberRef(state, m_ImageData, -1);
state.Pop(1);
}
+
}
Texture::~Texture()
diff --git a/Runtime/Graphics/Texture.h b/Runtime/Graphics/Texture.h index 0c66fa2..1aa8bdf 100644 --- a/Runtime/Graphics/Texture.h +++ b/Runtime/Graphics/Texture.h @@ -1,6 +1,6 @@ #pragma once #include <exception> - +#include <string> #include "Runtime/Lua/LuaHelper.h" #include "../Utilities/UtilMacros.h" #include "OpenGL.h" @@ -51,6 +51,11 @@ public: TextureException(const char* what) : std::exception(what) {} + TextureException(int glError) + { + g_sharedGLErrorMsg = std::to_string(glError); + std::exception(g_sharedGLErrorMsg.c_str()); + } }; class Texture : public LuaBind::NativeClass<Texture> diff --git a/Runtime/Scripting/Rendering/Texture.bind.cpp b/Runtime/Scripting/Rendering/Texture.bind.cpp index 061a303..2acbb1d 100644 --- a/Runtime/Scripting/Rendering/Texture.bind.cpp +++ b/Runtime/Scripting/Rendering/Texture.bind.cpp @@ -57,9 +57,10 @@ LUA_BIND_IMPL_METHOD(Texture, _New) setting.wrapMode = state.GetValue(5, (int)ETextureWrapMode::Clamp);
setting.filterMode = state.GetValue(6, (int)ETextureFilterMode::Linear);
+ Texture* tex = nullptr;
try
{
- Texture* tex = new Texture(state.GetVM(), setting, imgData);
+ tex = new Texture(state.GetVM(), setting, imgData);
tex->PushUserdata(state);
return 1;
}
|