Skip to content

Commit

Permalink
fix gl stencil on pc wechat game (cocos#8871)
Browse files Browse the repository at this point in the history
* support versionCompare util

* fix gl stencil
  • Loading branch information
PPpro authored Jun 24, 2021
1 parent d85cee1 commit 11287df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pal/minigame/wechat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IMiniGame, SystemInfo } from 'pal/minigame';
import { Orientation } from '../system/enum-type/orientation';
import { cloneObject, createInnerAudioContextPolyfill } from '../utils';
import { cloneObject, createInnerAudioContextPolyfill, versionCompare } from '../utils';

declare let wx: any;

Expand Down Expand Up @@ -131,7 +131,7 @@ minigame.getSafeArea = function () {
// #endregion SafeArea

// HACK: adapt GL.useProgram: use program not supported to unbind program on pc end
if (systemInfo.platform === 'windows') {
if (systemInfo.platform === 'windows' && versionCompare(systemInfo.SDKVersion, '2.16.0') < 0) {
// @ts-expect-error canvas defined in global
const locCanvas = canvas;
if (locCanvas) {
Expand Down
26 changes: 26 additions & 0 deletions pal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,29 @@ export function createInnerAudioContextPolyfill (minigameEnv: any, polyfillConfi
return audioContext;
};
}

/**
* Compare two version, version should in pattern like 3.0.0.
* If versionA > versionB, return number larger than 0.
* If versionA = versionB, return number euqal to 0.
* If versionA < versionB, return number smaller than 0.
* @param versionA
* @param versionB
*/
export function versionCompare (versionA: string, versionB: string): number {
const versionRegExp = /\d+\.\d+\.\d+/;
if (!(versionRegExp.test(versionA) && versionRegExp.test(versionB))) {
console.warn('wrong format of version when compare version');
return 0;
}
const versionNumbersA = versionA.split('.').map((num: string) => Number.parseInt(num));
const versionNumbersB = versionB.split('.').map((num: string) => Number.parseInt(num));
for (let i = 0; i < 3; ++i) {
const numberA = versionNumbersA[i];
const numberB = versionNumbersB[i];
if (numberA !== numberB) {
return numberA - numberB;
}
}
return 0;
}

0 comments on commit 11287df

Please sign in to comment.