Fix OGLES2HelloAPI and Vulkan build.
Assigning string literals to char* has been deprecated since C++98 and
is now an error in Visual Studio. Also, a goto which skips variable
nationalizations is an error now.
std::min/max are defined in <algorithm>
Bug swiftshader:121
Change-Id: Ic087706de810e68849eb021c1e0a9d2f2a960260
Reviewed-on: https://swiftshader-review.googlesource.com/c/21988
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/SwiftShader.sln b/SwiftShader.sln
index 9b4895f..8c5b30d 100644
--- a/SwiftShader.sln
+++ b/SwiftShader.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.27004.2002
+VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LLVM", "LLVM", "{B408B98A-E888-4ECF-81E0-7A37A6854B17}"
EndProject
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index 4d1f44a..9e03912 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -27,8 +27,10 @@
#include "VkPhysicalDevice.hpp"
#include "VkQueue.hpp"
#include "VkSemaphore.hpp"
+
#include <cstring>
#include <string>
+#include <algorithm>
extern "C"
{
@@ -1688,7 +1690,7 @@
UNIMPLEMENTED();
}
- // The only flag that can be set here is VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT
+ // The only flag that can be set here is VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT
// According to the Vulkan spec, 4.3.1. Queue Family Properties:
// "VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT specifies that the device queue is a
// protected-capable queue. If the protected memory feature is not enabled,
diff --git a/third_party/PowerVR_SDK/Examples/Beginner/01_HelloAPI/OGLES2/OGLES2HelloAPI_Windows.cpp b/third_party/PowerVR_SDK/Examples/Beginner/01_HelloAPI/OGLES2/OGLES2HelloAPI_Windows.cpp
index 4f2a734..947861c 100644
--- a/third_party/PowerVR_SDK/Examples/Beginner/01_HelloAPI/OGLES2/OGLES2HelloAPI_Windows.cpp
+++ b/third_party/PowerVR_SDK/Examples/Beginner/01_HelloAPI/OGLES2/OGLES2HelloAPI_Windows.cpp
@@ -4,7 +4,7 @@
@Title OpenGL ES 2.0 HelloAPI Tutorial
- @Version
+ @Version
@Copyright Copyright (c) Imagination Technologies Limited.
@@ -90,7 +90,7 @@
@Return bool true if no EGL error was detected
@Description Tests for an EGL error and prints it
******************************************************************************/
-bool TestEGLError(HWND hWnd, char* pszLocation)
+bool TestEGLError(HWND hWnd, const char* pszLocation)
{
/*
eglGetError returns the last error that has happened using egl,
@@ -110,6 +110,36 @@
}
/*!****************************************************************************
+ @Function Cleanup
+ @Input eglDisplay Handle to the EGL display
+ @Input hWnd Handle to the window
+ @Input hDC Handle to the device context
+ @Return int result code to OS
+ @Description Clean up before program termination on error or normal exit
+******************************************************************************/
+int Cleanup(EGLDisplay eglDisplay, HWND hWnd, HDC hDC)
+{
+ /*
+ eglTerminate takes care of destroying any context or surface created
+ with this display, so we don't need to call eglDestroySurface or
+ eglDestroyContext here.
+ */
+
+ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglTerminate(eglDisplay);
+
+ /*
+ Destroy the eglWindow.
+ This is platform specific and delegated to a separate function.
+ */
+
+ // Release the device context
+ if (hDC) ReleaseDC(hWnd, hDC);
+
+ return 0;
+}
+
+/*!****************************************************************************
@Function WinMain
@Input hInstance Application instance from OS
@Input hPrevInstance Always NULL
@@ -141,12 +171,12 @@
};
// Fragment and vertex shaders code
- char* pszFragShader = "\
+ const char* pszFragShader = "\
void main (void)\
{\
gl_FragColor = vec4(1.0, 1.0, 0.66 ,1.0);\
}";
- char* pszVertShader = "\
+ const char* pszVertShader = "\
attribute highp vec4 myVertex;\
uniform mediump mat4 myPMVMatrix;\
void main(void)\
@@ -192,7 +222,7 @@
if (!hDC)
{
MessageBox(0, _T("Failed to create the device context"), _T("Error"), MB_OK|MB_ICONEXCLAMATION);
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -220,7 +250,7 @@
if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))
{
MessageBox(0, _T("eglInitialize() failed."), _T("Error"), MB_OK|MB_ICONEXCLAMATION);
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -232,7 +262,7 @@
eglBindAPI(EGL_OPENGL_ES_API);
if (!TestEGLError(hWnd, "eglBindAPI"))
{
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -264,7 +294,7 @@
if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))
{
MessageBox(0, _T("eglChooseConfig() failed."), _T("Error"), MB_OK|MB_ICONEXCLAMATION);
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -286,7 +316,7 @@
if (!TestEGLError(hWnd, "eglCreateWindowSurface"))
{
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -299,7 +329,7 @@
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32ContextAttribs);
if (!TestEGLError(hWnd, "eglCreateContext"))
{
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -315,7 +345,7 @@
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
if (!TestEGLError(hWnd, "eglMakeCurrent"))
{
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/*
@@ -355,7 +385,7 @@
MessageBox(hWnd, i32InfoLogLength ? pszInfoLog : _T(""), _T("Failed to compile fragment shader"), MB_OK|MB_ICONEXCLAMATION);
delete[] pszInfoLog;
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
// Loads the vertex shader in the same way
@@ -375,7 +405,7 @@
delete[] pszInfoLog;
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
// Create the shader program
@@ -404,7 +434,7 @@
MessageBox(hWnd, i32InfoLogLength ? pszInfoLog : _T(""), _T("Failed to link program"), MB_OK|MB_ICONEXCLAMATION);
delete[] pszInfoLog;
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
// Actually use the created program
@@ -419,7 +449,7 @@
// We're going to draw a triangle to the screen so create a vertex buffer object for our triangle
GLuint ui32Vbo; // Vertex buffer object handle
-
+
// Interleaved vertex data
GLfloat afVertices[] = { -0.4f,-0.4f,0.0f, // Position
0.4f ,-0.4f,0.0f,
@@ -482,7 +512,7 @@
eglSwapBuffers(eglDisplay, eglSurface);
if (!TestEGLError(hWnd, "eglSwapBuffers"))
{
- goto cleanup;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
// Managing the window messages
@@ -503,24 +533,8 @@
/*
Step 10 - Terminate OpenGL ES and destroy the window (if present).
- eglTerminate takes care of destroying any context or surface created
- with this display, so we don't need to call eglDestroySurface or
- eglDestroyContext here.
*/
-cleanup:
- eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglTerminate(eglDisplay);
-
- /*
- Step 11 - Destroy the eglWindow.
- Again, this is platform specific and delegated to a separate function.
- */
-
- // Release the device context
- if (hDC) ReleaseDC(hWnd, hDC);
-
- // Destroy the eglWindow
- return 0;
+ return Cleanup(eglDisplay, hWnd, hDC);
}
/******************************************************************************