From 74faacd218c8277f9b7d6e3a6215dfd38a662212 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 6 Apr 2017 20:52:03 +0200 Subject: [PATCH 1/5] - fixed: FxVMFunctionCall::GetDirectFunction did not perform any checks on the function's self pointer and failed to report a mismatch as an error. - also fixed two places in the code where the above caused some incorrect definitions not to be detected. --- src/scripting/backend/codegen.cpp | 14 +++++++------- src/scripting/backend/codegen.h | 8 ++++---- src/scripting/backend/vmbuilder.cpp | 4 +++- wadsrc/static/zscript/inventory/inventory.txt | 2 +- wadsrc/static/zscript/strife/weaponassault.txt | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 4b70717b1..93fca44ed 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -419,7 +419,7 @@ bool FxExpression::isConstant() const // //========================================================================== -VMFunction *FxExpression::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxExpression::GetDirectFunction(PFunction *callingfunc, const VersionInfo &ver) { return nullptr; } @@ -8625,14 +8625,14 @@ bool FxVMFunctionCall::CheckAccessibility(const VersionInfo &ver) // //========================================================================== -VMFunction *FxVMFunctionCall::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxVMFunctionCall::GetDirectFunction(PFunction *callingfunc, const VersionInfo &ver) { // If this return statement calls a non-virtual function with no arguments, // then it can be a "direct" function. That is, the DECORATE // definition can call that function directly without wrapping // it inside VM code. - if (ArgList.Size() == 0 && !(Function->Variants[0].Flags & VARF_Virtual) && CheckAccessibility(ver)) + if (ArgList.Size() == 0 && !(Function->Variants[0].Flags & VARF_Virtual) && CheckAccessibility(ver) && CheckFunctionCompatiblity(ScriptPosition, callingfunc, Function)) { unsigned imp = Function->GetImplicitArgs(); if (Function->Variants[0].ArgFlags.Size() > imp && !(Function->Variants[0].ArgFlags[imp] & VARF_Optional)) return nullptr; @@ -9558,11 +9558,11 @@ ExpEmit FxSequence::Emit(VMFunctionBuilder *build) // //========================================================================== -VMFunction *FxSequence::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxSequence::GetDirectFunction(PFunction *func, const VersionInfo &ver) { if (Expressions.Size() == 1) { - return Expressions[0]->GetDirectFunction(ver); + return Expressions[0]->GetDirectFunction(func, ver); } return nullptr; } @@ -10544,11 +10544,11 @@ ExpEmit FxReturnStatement::Emit(VMFunctionBuilder *build) return out; } -VMFunction *FxReturnStatement::GetDirectFunction(const VersionInfo &ver) +VMFunction *FxReturnStatement::GetDirectFunction(PFunction *func, const VersionInfo &ver) { if (Args.Size() == 1) { - return Args[0]->GetDirectFunction(ver); + return Args[0]->GetDirectFunction(func, ver); } return nullptr; } diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 2974866ca..f90a03a53 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -324,7 +324,7 @@ public: virtual bool isConstant() const; virtual bool RequestAddress(FCompileContext &ctx, bool *writable); virtual PPrototype *ReturnProto(); - virtual VMFunction *GetDirectFunction(const VersionInfo &ver); + virtual VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); virtual bool CheckReturn() { return false; } virtual int GetBitValue() { return -1; } bool IsNumeric() const { return ValueType->isNumeric(); } @@ -1721,7 +1721,7 @@ public: ~FxVMFunctionCall(); FxExpression *Resolve(FCompileContext&); PPrototype *ReturnProto(); - VMFunction *GetDirectFunction(const VersionInfo &ver); + VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); ExpEmit Emit(VMFunctionBuilder *build); bool CheckEmitCast(VMFunctionBuilder *build, bool returnit, ExpEmit ®); TArray &GetReturnTypes() const @@ -1746,7 +1746,7 @@ public: FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); void Add(FxExpression *expr) { if (expr != NULL) Expressions.Push(expr); expr->NeedResult = false; } - VMFunction *GetDirectFunction(const VersionInfo &ver); + VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); bool CheckReturn(); }; @@ -1953,7 +1953,7 @@ public: ~FxReturnStatement(); FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); - VMFunction *GetDirectFunction(const VersionInfo &ver); + VMFunction *GetDirectFunction(PFunction *func, const VersionInfo &ver); bool CheckReturn() { return true; } }; diff --git a/src/scripting/backend/vmbuilder.cpp b/src/scripting/backend/vmbuilder.cpp index e4682432c..1543becd1 100644 --- a/src/scripting/backend/vmbuilder.cpp +++ b/src/scripting/backend/vmbuilder.cpp @@ -804,10 +804,12 @@ FFunctionBuildList FunctionBuildList; VMFunction *FFunctionBuildList::AddFunction(PNamespace *gnspc, const VersionInfo &ver, PFunction *functype, FxExpression *code, const FString &name, bool fromdecorate, int stateindex, int statecount, int lumpnum) { - auto func = code->GetDirectFunction(ver); + auto func = code->GetDirectFunction(functype, ver); if (func != nullptr) { delete code; + + return func; } diff --git a/wadsrc/static/zscript/inventory/inventory.txt b/wadsrc/static/zscript/inventory/inventory.txt index c526939a1..fe371ebea 100644 --- a/wadsrc/static/zscript/inventory/inventory.txt +++ b/wadsrc/static/zscript/inventory/inventory.txt @@ -53,7 +53,7 @@ class Inventory : Actor native native void ModifyDropAmount(int dropamount); native static void PrintPickupMessage (bool localview, String str); - States(Actor, Overlay, Weapon, Item) + States(Actor) { HideDoomish: TNT1 A 1050; diff --git a/wadsrc/static/zscript/strife/weaponassault.txt b/wadsrc/static/zscript/strife/weaponassault.txt index c382d8e84..c61951e1a 100644 --- a/wadsrc/static/zscript/strife/weaponassault.txt +++ b/wadsrc/static/zscript/strife/weaponassault.txt @@ -45,7 +45,7 @@ extend class StateProvider // //============================================================================ - void A_FireAssaultGun() + action void A_FireAssaultGun() { if (player == null) { From e690de25a89298b5c3bfb12689e3265d5625c830 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 7 Apr 2017 02:17:34 +0200 Subject: [PATCH 2/5] - Use SDL_GL_GetProcAddress on platforms where the SDL is being used. Since SDL initialized OpenGL for us, it is the only reliable way of retrieving proc addresses. - Check if ogl_LoadFunctions failed and make OpenGLSWFrameBuffer gracefully recover from that --- src/gl/system/gl_load.c | 4 +++- src/gl/system/gl_swframebuffer.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gl/system/gl_load.c b/src/gl/system/gl_load.c index 7075d6969..b0608ecb5 100644 --- a/src/gl/system/gl_load.c +++ b/src/gl/system/gl_load.c @@ -85,7 +85,9 @@ static PROC WinGetProcAddress(const char *name) #define IntGetProcAddress(name) AppleGLGetProcAddress(name) #else #if defined(__sgi) || defined(__sun) || defined(__unix__) - #define IntGetProcAddress(name) PosixGetProcAddress((const GLubyte*)name) + void* SDL_GL_GetProcAddress(const char* proc); + #define IntGetProcAddress(name) SDL_GL_GetProcAddress((const char*)name) + //#define IntGetProcAddress(name) PosixGetProcAddress((const GLubyte*)name) /* END OF MANUAL CHANGES, DO NOT REMOVE! */ #else /* GLX */ #include diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index ee5c0d58d..16138585d 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -194,7 +194,11 @@ OpenGLSWFrameBuffer::OpenGLSWFrameBuffer(void *hMonitor, int width, int height, static bool first = true; if (first) { - ogl_LoadFunctions(); + if (ogl_LoadFunctions() == ogl_LOAD_FAILED) + { + Printf("OpenGL load failed. No OpenGL acceleration will be used.\n"); + return; + } } gl_LoadExtensions(); InitializeState(); From b7482e10e2e5a11d7d1c8b368dc85a56dd3d9d66 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 7 Apr 2017 03:03:21 +0200 Subject: [PATCH 3/5] - Detect dinosaur OpenGL and refuse to use it --- src/gl/system/gl_swframebuffer.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 16138585d..b3de63eee 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -200,6 +200,19 @@ OpenGLSWFrameBuffer::OpenGLSWFrameBuffer(void *hMonitor, int width, int height, return; } } + + const char *glversion = (const char*)glGetString(GL_VERSION); + bool isGLES = (glversion && strlen(glversion) > 10 && memcmp(glversion, "OpenGL ES ", 10) == 0); + if (isGLES && ogl_IsVersionGEQ(2, 0) == 0) + { + Printf("OpenGL acceleration requires at least OpenGL ES 2.0. No Acceleration will be used.\n"); + return; + } + else if (!isGLES && ogl_IsVersionGEQ(3, 0) == 0) + { + Printf("OpenGL acceleration requires at least OpenGL 3.0. No Acceleration will be used.\n"); + return; + } gl_LoadExtensions(); InitializeState(); if (first) From 85a9984807c4074fffacf662838b3884baaf392f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 7 Apr 2017 04:09:04 +0200 Subject: [PATCH 4/5] - Add OpenGL ES 3 support to GL renderer --- src/gl/shaders/gl_shader.cpp | 18 ++++++++++++++---- src/gl/system/gl_interface.cpp | 1 + wadsrc/static/shaders/glsl/fuzz_noise.fp | 2 +- wadsrc/static/shaders/glsl/fuzz_standard.fp | 2 +- wadsrc/static/shaders/glsl/main.fp | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 44be65ebe..2fdf9fbf3 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -85,8 +85,11 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * unsigned int lightbuffersize = GLRenderer->mLights->GetBlockSize(); if (lightbuffertype == GL_UNIFORM_BUFFER) { - // This differentiation is for some Intel drivers which fail on #extension, so use of #version 140 is necessary - if (gl.glslversion < 1.4f) + if (gl.es) + { + vp_comb.Format("#version 300 es\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize); + } + else if (gl.glslversion < 1.4f) // This differentiation is for some Intel drivers which fail on #extension, so use of #version 140 is necessary { vp_comb.Format("#version 130\n#extension GL_ARB_uniform_buffer_object : require\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize); } @@ -411,8 +414,15 @@ FShaderManager::FShaderManager() { if (!gl.legacyMode) { - for (int passType = 0; passType < MAX_PASS_TYPES; passType++) - mPassShaders.Push(new FShaderCollection((EPassType)passType)); + if (gl.es) // OpenGL ES does not support multiple fragment shader outputs. As a result, no GBUFFER passes are possible. + { + mPassShaders.Push(new FShaderCollection(NORMAL_PASS)); + } + else + { + for (int passType = 0; passType < MAX_PASS_TYPES; passType++) + mPassShaders.Push(new FShaderCollection((EPassType)passType)); + } } } diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index a0d16597f..1a3f4b1ae 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -176,6 +176,7 @@ void gl_LoadExtensions() gl.legacyMode = false; gl.lightmethod = LM_DEFERRED; gl.buffermethod = BM_DEFERRED; + gl.flags |= RFL_NO_CLIP_PLANES; } else { diff --git a/wadsrc/static/shaders/glsl/fuzz_noise.fp b/wadsrc/static/shaders/glsl/fuzz_noise.fp index 17f15d03b..75afc251f 100644 --- a/wadsrc/static/shaders/glsl/fuzz_noise.fp +++ b/wadsrc/static/shaders/glsl/fuzz_noise.fp @@ -5,7 +5,7 @@ vec4 ProcessTexel() { vec2 texCoord = vTexCoord.st; vec4 basicColor = getTexel(texCoord); - ivec2 texSize = textureSize(tex, 0); + vec2 texSize = vec2(textureSize(tex, 0)); texCoord.x = float( int(texCoord.x * texSize.x) ) / texSize.x; texCoord.y = float( int(texCoord.y * texSize.y) ) / texSize.y; diff --git a/wadsrc/static/shaders/glsl/fuzz_standard.fp b/wadsrc/static/shaders/glsl/fuzz_standard.fp index 95ba52431..b467f64b2 100644 --- a/wadsrc/static/shaders/glsl/fuzz_standard.fp +++ b/wadsrc/static/shaders/glsl/fuzz_standard.fp @@ -5,7 +5,7 @@ vec4 ProcessTexel() { vec2 texCoord = vTexCoord.st; vec4 basicColor = getTexel(texCoord); - ivec2 texSize = textureSize(tex, 0); + vec2 texSize = vec2(textureSize(tex, 0)); texCoord.x = float( int(texCoord.x * texSize.x) ) / texSize.x; texCoord.y = float( int(texCoord.y * texSize.y) ) / texSize.y; diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 9a682f386..5b4d1438f 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -90,7 +90,7 @@ vec4 getTexel(vec2 st) } break; } - if (uObjectColor2.a == 0) texel *= uObjectColor; + if (uObjectColor2.a == 0.0) texel *= uObjectColor; else texel *= mix(uObjectColor, uObjectColor2, glowdist.z); return desaturate(texel); From b1e1f25218e008ef8cca33ec831c93f00bcd5e3f Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Thu, 6 Apr 2017 23:29:15 -0400 Subject: [PATCH 5/5] - detect gl es shaders and request them --- src/gl/shaders/gl_shaderprogram.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gl/shaders/gl_shaderprogram.cpp b/src/gl/shaders/gl_shaderprogram.cpp index 5327eeac0..dfb46c544 100644 --- a/src/gl/shaders/gl_shaderprogram.cpp +++ b/src/gl/shaders/gl_shaderprogram.cpp @@ -216,7 +216,10 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const FString patchedCode; int shaderVersion = MIN((int)round(gl.glslversion * 10) * 10, maxGlslVersion); - patchedCode.AppendFormat("#version %d\n", shaderVersion); + if (gl.es) + patchedCode.AppendFormat("#version %d es\n", shaderVersion); + else + patchedCode.AppendFormat("#version %d\n", shaderVersion); // TODO: Find some way to add extension requirements to the patching //