mirror of https://github.com/axmolengine/axmol.git
removed old files
This commit is contained in:
parent
6005ffd89d
commit
3795d6ac28
|
@ -1,161 +0,0 @@
|
||||||
// Based on Hello_Triangle.c from
|
|
||||||
// Book: OpenGL(R) ES 2.0 Programming Guide
|
|
||||||
// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
|
|
||||||
// ISBN-10: 0321502795
|
|
||||||
// ISBN-13: 9780321502797
|
|
||||||
// Publisher: Addison-Wesley Professional
|
|
||||||
// URLs: http://safari.informit.com/9780321563835
|
|
||||||
// http://www.opengles-book.com
|
|
||||||
|
|
||||||
//
|
|
||||||
// This file is used by the template to render a basic scene using GL.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "pch.h"
|
|
||||||
#include "HelloTriangleRenderer.h"
|
|
||||||
|
|
||||||
// These are used by the shader compilation methods.
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using namespace Platform;
|
|
||||||
|
|
||||||
using namespace cpp_tests;
|
|
||||||
|
|
||||||
#define STRING(s) #s
|
|
||||||
|
|
||||||
GLuint CompileShader(GLenum type, const std::string &source)
|
|
||||||
{
|
|
||||||
GLuint shader = glCreateShader(type);
|
|
||||||
|
|
||||||
const char *sourceArray[1] = { source.c_str() };
|
|
||||||
glShaderSource(shader, 1, sourceArray, NULL);
|
|
||||||
glCompileShader(shader);
|
|
||||||
|
|
||||||
GLint compileResult;
|
|
||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
|
|
||||||
|
|
||||||
if (compileResult == 0)
|
|
||||||
{
|
|
||||||
GLint infoLogLength;
|
|
||||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
|
|
||||||
|
|
||||||
std::vector<GLchar> infoLog(infoLogLength);
|
|
||||||
glGetShaderInfoLog(shader, (GLsizei)infoLog.size(), NULL, infoLog.data());
|
|
||||||
|
|
||||||
std::wstring errorMessage = std::wstring(L"Shader compilation failed: ");
|
|
||||||
errorMessage += std::wstring(infoLog.begin(), infoLog.end());
|
|
||||||
|
|
||||||
throw Exception::CreateException(E_FAIL, ref new Platform::String(errorMessage.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint CompileProgram(const std::string &vsSource, const std::string &fsSource)
|
|
||||||
{
|
|
||||||
GLuint program = glCreateProgram();
|
|
||||||
|
|
||||||
if (program == 0)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Program creation failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
|
|
||||||
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
|
|
||||||
|
|
||||||
if (vs == 0 || fs == 0)
|
|
||||||
{
|
|
||||||
glDeleteShader(fs);
|
|
||||||
glDeleteShader(vs);
|
|
||||||
glDeleteProgram(program);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
glAttachShader(program, vs);
|
|
||||||
glDeleteShader(vs);
|
|
||||||
|
|
||||||
glAttachShader(program, fs);
|
|
||||||
glDeleteShader(fs);
|
|
||||||
|
|
||||||
glLinkProgram(program);
|
|
||||||
|
|
||||||
GLint linkStatus;
|
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
|
|
||||||
|
|
||||||
if (linkStatus == 0)
|
|
||||||
{
|
|
||||||
GLint infoLogLength;
|
|
||||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
|
|
||||||
|
|
||||||
std::vector<GLchar> infoLog(infoLogLength);
|
|
||||||
glGetProgramInfoLog(program, (GLsizei)infoLog.size(), NULL, infoLog.data());
|
|
||||||
|
|
||||||
std::wstring errorMessage = std::wstring(L"Program link failed: ");
|
|
||||||
errorMessage += std::wstring(infoLog.begin(), infoLog.end());
|
|
||||||
|
|
||||||
throw Exception::CreateException(E_FAIL, ref new Platform::String(errorMessage.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return program;
|
|
||||||
}
|
|
||||||
|
|
||||||
HelloTriangleRenderer::HelloTriangleRenderer() :
|
|
||||||
mProgram(0)
|
|
||||||
{
|
|
||||||
// Vertex Shader source
|
|
||||||
const std::string vs = STRING
|
|
||||||
(
|
|
||||||
attribute vec4 vPosition;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vPosition;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fragment Shader source
|
|
||||||
const std::string fs = STRING
|
|
||||||
(
|
|
||||||
precision mediump float;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// CompileProgram will throw if it fails, so we don't need to check for success.
|
|
||||||
mProgram = CompileProgram(vs, fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
HelloTriangleRenderer::~HelloTriangleRenderer()
|
|
||||||
{
|
|
||||||
if (mProgram != 0)
|
|
||||||
{
|
|
||||||
glDeleteProgram(mProgram);
|
|
||||||
mProgram = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draws a basic triangle
|
|
||||||
void HelloTriangleRenderer::Draw(GLsizei width, GLsizei height)
|
|
||||||
{
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
|
|
||||||
GLfloat vertices[] =
|
|
||||||
{
|
|
||||||
0.0f, 0.5f, 0.0f,
|
|
||||||
-0.5f, -0.5f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
glUseProgram(mProgram);
|
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "pch.h"
|
|
||||||
|
|
||||||
namespace cpp_tests
|
|
||||||
{
|
|
||||||
class HelloTriangleRenderer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
HelloTriangleRenderer();
|
|
||||||
~HelloTriangleRenderer();
|
|
||||||
void Draw(GLsizei width, GLsizei height);
|
|
||||||
|
|
||||||
private:
|
|
||||||
GLuint mProgram;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,153 +0,0 @@
|
||||||
#include "pch.h"
|
|
||||||
|
|
||||||
using namespace Platform;
|
|
||||||
using namespace Windows::UI::Xaml::Controls;
|
|
||||||
using namespace Windows::Foundation;
|
|
||||||
using namespace Windows::Foundation::Collections;
|
|
||||||
|
|
||||||
OpenGLES::OpenGLES() :
|
|
||||||
mEglConfig(nullptr),
|
|
||||||
mEglDisplay(EGL_NO_DISPLAY),
|
|
||||||
mEglContext(EGL_NO_CONTEXT)
|
|
||||||
{
|
|
||||||
Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGLES::~OpenGLES()
|
|
||||||
{
|
|
||||||
Cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLES::Initialize()
|
|
||||||
{
|
|
||||||
const EGLint configAttributes[] =
|
|
||||||
{
|
|
||||||
EGL_RED_SIZE, 8,
|
|
||||||
EGL_GREEN_SIZE, 8,
|
|
||||||
EGL_BLUE_SIZE, 8,
|
|
||||||
EGL_ALPHA_SIZE, 8,
|
|
||||||
EGL_DEPTH_SIZE, 8,
|
|
||||||
EGL_STENCIL_SIZE, 8,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
const EGLint displayAttributes[] =
|
|
||||||
{
|
|
||||||
// This can be used to configure D3D11. For example, EGL_PLATFORM_ANGLE_TYPE_D3D11_FL9_3_ANGLE could be used.
|
|
||||||
// This would ask the graphics card to use D3D11 Feature Level 9_3 instead of Feature Level 11_0+.
|
|
||||||
// On Windows Phone, this would allow the Phone Emulator to act more like the GPUs that are available on real Phone devices.
|
|
||||||
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
|
|
||||||
EGL_NONE,
|
|
||||||
};
|
|
||||||
|
|
||||||
const EGLint contextAttributes[] =
|
|
||||||
{
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
// eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in 'displayAttributes' to configure D3D11.
|
|
||||||
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));
|
|
||||||
if (!eglGetPlatformDisplayEXT)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT");
|
|
||||||
}
|
|
||||||
|
|
||||||
mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
|
|
||||||
if (mEglDisplay == EGL_NO_DISPLAY)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to get default EGL display");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL");
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint numConfigs = 0;
|
|
||||||
if (eglGetConfigs(mEglDisplay, NULL, 0, &numConfigs) == EGL_FALSE)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to get EGLConfig count");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &numConfigs) == EGL_FALSE)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to choose first EGLConfig");
|
|
||||||
}
|
|
||||||
|
|
||||||
mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, contextAttributes);
|
|
||||||
if (mEglContext == EGL_NO_CONTEXT)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to create EGL context");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLES::Cleanup()
|
|
||||||
{
|
|
||||||
if (mEglDisplay != EGL_NO_DISPLAY && mEglContext != EGL_NO_CONTEXT)
|
|
||||||
{
|
|
||||||
eglDestroyContext(mEglDisplay, mEglContext);
|
|
||||||
mEglContext = EGL_NO_CONTEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mEglDisplay != EGL_NO_DISPLAY)
|
|
||||||
{
|
|
||||||
eglTerminate(mEglDisplay);
|
|
||||||
mEglDisplay = EGL_NO_DISPLAY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLES::Reset()
|
|
||||||
{
|
|
||||||
Cleanup();
|
|
||||||
Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLSurface OpenGLES::CreateSurface(SwapChainPanel^ panel, const Size* renderSurfaceSize)
|
|
||||||
{
|
|
||||||
if (!panel)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_INVALIDARG, L"SwapChainPanel parameter is invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLSurface surface = EGL_NO_SURFACE;
|
|
||||||
|
|
||||||
// Create a PropertySet and initialize with the EGLNativeWindowType.
|
|
||||||
PropertySet^ surfaceCreationProperties = ref new PropertySet();
|
|
||||||
surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), panel);
|
|
||||||
|
|
||||||
// If a render surface size is specified, add it to the surface creation properties
|
|
||||||
if (renderSurfaceSize != nullptr)
|
|
||||||
{
|
|
||||||
surfaceCreationProperties->Insert(ref new String(EGLRenderSurfaceSizeProperty), PropertyValue::CreateSize(*renderSurfaceSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, reinterpret_cast<IInspectable*>(surfaceCreationProperties), NULL);
|
|
||||||
if (surface == EGL_NO_SURFACE)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to create EGL surface");
|
|
||||||
}
|
|
||||||
|
|
||||||
return surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLES::DestroySurface(const EGLSurface surface)
|
|
||||||
{
|
|
||||||
if (mEglDisplay != EGL_NO_DISPLAY && surface != EGL_NO_SURFACE)
|
|
||||||
{
|
|
||||||
eglDestroySurface(mEglDisplay, surface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLES::MakeCurrent(const EGLSurface surface)
|
|
||||||
{
|
|
||||||
if (eglMakeCurrent(mEglDisplay, surface, surface, mEglContext) == EGL_FALSE)
|
|
||||||
{
|
|
||||||
throw Exception::CreateException(E_FAIL, L"Failed to make EGLSurface current");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLBoolean OpenGLES::SwapBuffers(const EGLSurface surface)
|
|
||||||
{
|
|
||||||
return (eglSwapBuffers(mEglDisplay, surface));
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
class OpenGLES
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OpenGLES();
|
|
||||||
~OpenGLES();
|
|
||||||
|
|
||||||
EGLSurface CreateSurface(Windows::UI::Xaml::Controls::SwapChainPanel^ panel, const Windows::Foundation::Size* renderSurfaceSize);
|
|
||||||
void DestroySurface(const EGLSurface surface);
|
|
||||||
void MakeCurrent(const EGLSurface surface);
|
|
||||||
EGLBoolean SwapBuffers(const EGLSurface surface);
|
|
||||||
void Reset();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void Initialize();
|
|
||||||
void Cleanup();
|
|
||||||
|
|
||||||
private:
|
|
||||||
EGLDisplay mEglDisplay;
|
|
||||||
EGLContext mEglContext;
|
|
||||||
EGLConfig mEglConfig;
|
|
||||||
};
|
|
|
@ -1 +0,0 @@
|
||||||
#include "pch.h"
|
|
|
@ -1,27 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <wrl.h>
|
|
||||||
#include <wrl/client.h>
|
|
||||||
#include <memory>
|
|
||||||
#include <agile.h>
|
|
||||||
#include <concrt.h>
|
|
||||||
#include <collection.h>
|
|
||||||
#include <ppltasks.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
// OpenGL ES includes
|
|
||||||
#include <GLES3/gl3.h>
|
|
||||||
#include <GLES3/gl3ext.h>
|
|
||||||
|
|
||||||
// EGL includes
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
#include <EGL/eglext.h>
|
|
||||||
#include <EGL/eglplatform.h>
|
|
||||||
#include <angle_windowsstore.h>
|
|
||||||
|
|
||||||
#include "OpenGLES.h"
|
|
||||||
#include "HelloTriangleRenderer.h"
|
|
||||||
#include "App.xaml.h"
|
|
||||||
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#include "cocos-ext.h"
|
|
Loading…
Reference in New Issue